기존 g4를 g5로 변경하려 합니다. 살펴봐 주십시오.
본문
다음 식으로 각 게시판의 이미지를 추출하려고 하니까,
오류가 나거나 출력이 안되네요.
<? for ($i=0; $i<count($list); $i++) {
$data_path = G5_URL.'/data/file/{$list[$i][bo_table]}';
$thumb_path = $data_path.'/scrthumb';
@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
$thumb = $thumb_path.'/'.$list[$i][wr_id];
if ($i && $i%$mod==0)
echo "</tr><tr><td colspan='{$mod}' height=20></td></tr><tr>";
$img = "<img src='$member_skin_url/img/scr2_noimg.gif' border=0 title='이미지 없음'>";
$image = $list[$i][bf_file];
// 썸네일 이미지가 존재하지 않는다면
if (!file_exists($thumb)) {
$file = G5_URL.'/data/file/' .$list[$i][bo_table] .'/' .$list[$i][bf_file];
//$file = $list[$i][file][0][path] .'/'. $list[$i][bf_file];
// 업로드된 파일이 이미지라면
if (preg_match("/\.(jpg|gif|png)$/i", $file) && file_exists($file)) { // 첨부파일 이미지 썸네일
$size = getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
continue;
$rate = $thumb_width / $size[0];
$height = (int)($size[1] * $rate);
// 계산된 썸네일 이미지의 높이가 설정된 이미지의 높이보다 작다면
if ($height < $thumb_height)
// 계산된 이미지 높이로 복사본 이미지 생성
$dst = imagecreatetruecolor($thumb_width, $height);
else
// 설정된 이미지 높이로 복사본 이미지 생성
$dst = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thumb_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][wr_id], $thumb_quality);
chmod($thumb_path.'/'.$list[$i][wr_id], 0606);
} else { //에디터 이미지 썸네일
$edit_img = $list[$i]['wr_content'];
if (eregi("data/geditor/[^<>]*\.(gif|jp[e]?g|png|bmp)", $edit_img, $tmp)) { //체디터 사용자는 data/cheditor 로 변경하세요.
$file = '../' . $tmp[0]; // 파일명
$size = getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
continue;
$rate = $thumb_width / $size[0];
$height = (int)($size[1] * $rate);
// 계산된 썸네일 이미지의 높이가 설정된 이미지의 높이보다 작다면
if ($height < $thumb_height)
// 계산된 이미지 높이로 복사본 이미지 생성
$dst = imagecreatetruecolor($thumb_width, $height);
else
// 설정된 이미지 높이로 복사본 이미지 생성
$dst = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $thumb_width, $height, $size[0], $size[1]);
imagejpeg($dst, $thumb_path.'/'.$list[$i][wr_id], $thumb_quality);
chmod($thumb_path.'/'.$list[$i][wr_id], 0606);
}
}
}
//썸네일 출력
if (file_exists($thumb) && $list[$i][bf_file])
$img = "<a href=\"G5_URL.'/data/file/{$list[$i][bo_table]}/$image'\" class='highslide' onclick='return hs.expand(this)'><img src='{$thumb}' border='0' style='border:0px solid #999999;'></a>";
else if (file_exists($thumb) && preg_match("`<\s*img\s+src\s*=\s*['|\"]?([^'|\"\s]+://[^'|\"\s]+\.(gif|jpe?g|png))['|\"]?\s*[^>]+`i", $list[$i]['wr_content'], $images))
$img = "<a href='$images[1]' class='highslide' onclick='return hs.expand(this)'><img src='{$thumb}' border='0' style='border:0px solid #999999;'></a>";
else
$img = "<img src='$member_skin_url/img/scr2_noimg.gif' border=0 title='이미지 없음'>";
?>
특히, "썸네일 출력" 부분을 추출하려는데 잘 안되네요.
위의 식을 어떻게 잡아줘야 할까요...
도움 부탁 드립니다.(__)
!-->답변 1
$g4['path']를 G5_URL로만 바꾸면 다 되는건 아니구요..
실제로 그누보드4용 스킨이나 플러그인들에는 상대경로가 쓰여서 저런식으로 많이 사용했는데요.. 문제가 되는곳은 file_exists() 나 is_file(), getimagesize() 같은 부분입니다. 여기는 url이 아닌 서버의 운영체제상의 경로를 사용하고 출력할때는 url로 출력해주는걸로 나눠서 처리해줘야 합니다.
경로들 잡히는 곳들을 여러군데 수정해줘야 할겁니다.
$data_path = G5_PATH.'/data/file/{$list[$i][bo_table]}';
$data_url = G5_URL.'/data/file/{$list[$i][bo_table]}';
$thumb_dir_path = $data_path.'/scrthumb';
$thumb_dir_url = $data_url.'/scrthumb';
$thumb = $thumb_dir_path.'/'.$list[$i][wr_id];
$thumb_url = $thumb_dir_url.'/'.$list[$i][wr_id];
이런식으로 하시고 맨 마지막은
//썸네일 출력
if (file_exists($thumb) && $list[$i][bf_file])
$img = "<a href=\"{$data_url}/$image'\" class='highslide' onclick='return hs.expand(this)'><img src='{$thumb_url}' border='0' style='border:0px solid #999999;'></a>";
else if (file_exists($thumb) && preg_match("`<\s*img\s+src\s*=\s*['|\"]?([^'|\"\s]+://[^'|\"\s]+\.(gif|jpe?g|png))['|\"]?\s*[^>]+`i", $list[$i]['wr_content'], $images))
$img = "<a href='$images[1]' class='highslide' onclick='return hs.expand(this)'><img src='{$thumb_url}' border='0' style='border:0px solid #999999;'></a>";
else
$img = "<img src='$member_skin_url/img/scr2_noimg.gif' border=0 title='이미지 없음'>";
수정이 너무 많아 귀찮다 하실땐..
http://sir.co.kr/bbs/board.php?bo_table=g5_tip&wr_id=2372
이걸 적용하시고 $g4['path']로 되있던 부분을 G5_PATH2로 바꾸시면 되긴 합니다만 가급적 원본에 맞추고자 위 답변을 먼저 드렸습니다.
!-->!-->
답변을 작성하시기 전에 로그인 해주세요.