썸네일 파일명 생성시 중복 처리 질문드립니다 채택완료
천천히한걸음
6년 전
조회 3,454
</p>
<p>public static function makeThumb($src_path, $thumb_dir, $w, $h, $options=array()){</p>
<p> $temp = BFiledir::parseFilename($src_path);
$fname = $temp["name"];
$ext = $temp["extension"];</p>
<p> //원본파일이 없으면
if($fname!="" && is_file($src_path)){
//애니메이션 GIF이면 원본그대로
if(BImageutil::isAnimatedGif($src_path) && $options['is_anigif_thumb']==false){
list($t_w, $t_h) = BImageutil::rateLimit($src_path, $w, $h);
$filename = $fname.'.'.$ext;
$arr = array(
$fname.'.'.$ext,
$t_w,
$t_h,
'filename' => $filename,
'width' => $t_w,
'height' => $t_h
);</p>
<p>
//애니메이션이 아니면
}else{
if($options['keep_filename']){
$filename = $fname.".".$ext;
}else{
$str= "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //중복방지문자
$temp= str_shuffle($str);
$ret = substr($temp, 0, 1);
$filename = $fname."".$ret.".".$ext;
}else{
$temp1 = "l";
$filename = $fname."".$temp1.".".$ext;
}</p>
<p> $thumb_path = $thumb_dir."/".$filename;
//썸네일이 존재하지 않으면
if(!is_file($thumb_path)){
BFiledir::autoMkDir($thumb_dir, 0755);
$t = new BThumbnail($src_path, $thumb_path, $w, $h, $options);
$t->save();
list($t_w, $t_h) = $t->getThumbSize();
//썸네일이 존재하면
}else{
list($t_w, $t_h) = BImageutil::getImageSize($thumb_path);
}</p>
<p> $arr = array(
$filename,
$t_w,
$t_h,
"filename" => $filename,
"width" => $t_w,
"height" => $t_h
);
}
}</p>
<p> return $arr;
}
}</p>
<p>
이렇게 했는데 썸네일파일명이 중복처리를 하고 싶습니다
일단 셔플로 돌려서 하나씩 짤라서 넣는방법을 했지만 아닌거 같아서 잘 알려주시분 계신가요?
예)
썸네일 파일명이 apple.jpg 이라고 저장이되고 만약에 같은 파일명이 생기다면 뒷에 미리정해놓은 숫자 또는 영어를 마지막에 하나 더 붙혀서 appleA.jpg 이런식으로 처리하고 싶습니다
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
6년 전
아래 소스를 참조해서 수정해보세요..
</p>
<p>$ret=0;</p>
<p><span style="font-family:맑은 고딕;"><span style="font-size:11pt;">do {</span></span></p>
<p><span style="font-family:맑은 고딕;"><span style="font-size:11pt;"> $ret++;</span></span></p>
<p><span style="font-family:맑은 고딕;"><span style="font-size:11pt;"> </span></span><code>$filename</code> <code>= </code><code>$fname</code><code>.</code><code>""</code><code>.</code><code>$ret</code><code>.</code><code>"."</code><code>.</code><code>$ext</code><code>;</code></p>
<p><code> $thumb_path</code> <code>= </code><code>$thumb_dir</code><code>.</code><code>"/"</code><code>.</code><code>$filename</code><code>;</code></p>
<p><span style="font-family:맑은 고딕;"><span style="font-size:11pt;">} while(<code>is_file</code><code>(</code><code>$thumb_path</code><code>))</code></span></span></p>
<p><span style="font-family:맑은 고딕;"><span style="font-size:11pt;"><code>
로그인 후 평가할 수 있습니다
답변에 대한 댓글 2개
�
천천히한걸음
6년 전
e
eyekiss
6년 전
하다가 안되면 쪽지 주세요..^^
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
참고 해서 작업하고있는데 에러나 나는군요 ㅠ
계속 도전해보겠습니다