썸네일을 사용한 갤러리 사용시 리스트화면과 최신글의 이미지에서의 문제점. 정보
썸네일을 사용한 갤러리 사용시 리스트화면과 최신글의 이미지에서의 문제점.
본문
안녕하세요. 또 한가지 안풀리는 부분이 있어서 문의 드려 봅니다.
썸네일을 사용한 갤러리게시판등을 사용시 올려진 게시물을 수정하였을 경우
목록에서는 이미지가 바뀌나 리스트나 최신글에서는 썸네일 파일이 바뀐이미지로 수정되지 않고 예전 이미지가 보여지는 문제가 있었습니다.
하지만 이건 예전에 유아원님께서 알려주신 아래와 같은 방법으로 해결할수 있었습니다.
기존소스
$img = "<img src='$latest_skin_path/img/no_image.gif' border=0 title='이미지 없음'>";
$thumb = $thumb_path.'/'.$list[$i][wr_id];
if (!file_exists($thumb))
$thumb = $thumb_path.'/'.$list[$i][wr_id];
if (!file_exists($thumb))
를
아래와 같이 수정하면 이미지가 제대로 바뀌었습니다.
$img = "<img src='$latest_skin_path/img/no_image.gif' border=0 title='이미지 없음'>";
$filename = $list[$i]['file'][0]['file'];
$thumb = $thumb_path.'/' . $filename;
if (!file_exists($thumb))
$filename = $list[$i]['file'][0]['file'];
$thumb = $thumb_path.'/' . $filename;
if (!file_exists($thumb))
그외 몇군데 더 바꾸어준 부분이 있구요.
그런데... 또 여기서 문제가 하나 생겨서요.
간혹 게시물에 내용만 있고, 이미지가 없을 경우가 있으면 자동으로 No image 파일이 보여져야 하는데...
저렇게 소스를 수정하고 나면 No image 파일이 보여지지 않고 그냥 엑박만 나옵니다.
그 엑박 이미지의 경로는 그누보드경로/data/file/게시판이름/thumb/ 이거이구요.
그래서 이리 저리 수정을 해볼려고 했지만... 제대로 되지를 않네요.
$img = "<img src='$latest_skin_path/img/no_image.gif' border=0 title='이미지 없음'>";
$filename = $list[$i]['file'][0]['file'];
$thumb = $thumb_path.'/'.$list[$i][wr_id];
if (!file_exists($thumb))
이런식으로 바꾸면 이미지가 있어도 다 No image 파일만 나와버리구요.
-----------------------------------------------------------------------------------------
$img = "<img src='$latest_skin_path/img/no_image.gif' border=0 title='이미지 없음'>";
$thumb = $thumb_path.'/'.$list[$i][wr_id];
if (!file_exists($thumb))
이런식으로 바꾸면 모두 엑박이 되어 버리구요.
어디를 손보면 정상적으로 제가 원하는대로 될수 있는건지요?
혹시나 해서 제가 사용하고 있는 최실글(이미지) 소스도 첨부하여 봅니다.
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if (!$board[bo_4]) alert("해당 게시판 설정 : 여분 필드 4 에 목록에서 보여질 이미지의 폭을 설정하십시오. (픽셀 단위)");
if (!$board[bo_5]) alert("해당 게시판 설정 : 여분 필드 5 에 목록에서 보여질 이미지의 질(quality)을 비율로 설정하십시오. (100 이하)");
if (!function_exists("imagecopyresampled")) alert("GD 2.0.1 이상 버전이 설치되어 있어야 사용할 수 있는 스킨 입니다.");
if (!$board[bo_5]) alert("해당 게시판 설정 : 여분 필드 5 에 목록에서 보여질 이미지의 질(quality)을 비율로 설정하십시오. (100 이하)");
if (!function_exists("imagecopyresampled")) alert("GD 2.0.1 이상 버전이 설치되어 있어야 사용할 수 있는 스킨 입니다.");
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';
$thumb_path = $data_path.'/thumb';
@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
@chmod($thumb_path, 0707);
?>
<!-- <?=$board[bo_subject]?> (<?=$board[bo_table]?>) 최신글 -->
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
<tr><td align="center">
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
<tr><td align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="630" height="15"><a href='<?=$g4[bbs_path]?>/board.php?bo_table=<?=$bo_table?>'><img src="<?=$latest_skin_path?>/img/title.gif" width="630" height="15" BORDER="0"></a></td>
</tr>
</table>
<tr>
<td width="630" height="15"><a href='<?=$g4[bbs_path]?>/board.php?bo_table=<?=$bo_table?>'><img src="<?=$latest_skin_path?>/img/title.gif" width="630" height="15" BORDER="0"></a></td>
</tr>
</table>
</td></tr>
<tr><td align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<?
for ($i=0; $i<count($list); $i++)
{
if ($i > 0)
echo "<td width=20> </td>";
<tr>
<?
for ($i=0; $i<count($list); $i++)
{
if ($i > 0)
echo "<td width=20> </td>";
$img = "<img src='$latest_skin_path/img/no_image.gif' border=0 title='이미지 없음'>";
$filename = $list[$i]['file'][0]['file'];
$thumb = $thumb_path.'/' . $filename;
if (!file_exists($thumb))
{
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
if (preg_match("/\.(jp[e]?g|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
break;
$filename = $list[$i]['file'][0]['file'];
$thumb = $thumb_path.'/' . $filename;
if (!file_exists($thumb))
{
$file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
if (preg_match("/\.(jp[e]?g|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
break;
$rate = $board[bo_4] / $size[0];
$height = (int)($size[1] * $rate);
$height = (int)($size[1] * $rate);
$dst = imagecreatetruecolor($board[bo_4], $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $board[bo_4], $height, $size[0], $size[1]);
imagepng($dst, $thumb_path.'/' . $filename, $board[bo_5]);
chmod($thumb_path.'/' . $filename, 0606);
}
}
imagecopyresampled($dst, $src, 0, 0, 0, 0, $board[bo_4], $height, $size[0], $size[1]);
imagepng($dst, $thumb_path.'/' . $filename, $board[bo_5]);
chmod($thumb_path.'/' . $filename, 0606);
}
}
if (file_exists($thumb))
$img = "<img src='$thumb' border=0>";
$img = "<img src='$thumb' border=0>";
$href = "$g4[bbs_path]/board.php?bo_table=$bo_table";
echo <<<HEREDOC
<td valign="top" align="center">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="5" align="center"></td>
</tr>
<td valign="top" align="center">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="5" align="center"></td>
</tr>
<tr>
<td align=center width='135' height='101' style='width:135px;height:101px;border:1px solid #E1E1E1; padding:6px'><div style='width:135px; height:101px; position: relative; overflow:hidden;' align=center><a href='{$list[$i][href]}' onfocus='this.blur()'>{$img}</a></div></td>
</tr>
<td align=center width='135' height='101' style='width:135px;height:101px;border:1px solid #E1E1E1; padding:6px'><div style='width:135px; height:101px; position: relative; overflow:hidden;' align=center><a href='{$list[$i][href]}' onfocus='this.blur()'>{$img}</a></div></td>
</tr>
</tr>
<tr>
<td height="5" align="center"></td>
</tr>
<td height="5" align="center"></td>
</tr>
<tr>
<td width="135" height="20" align="center" class="sub">
<table width="135" height="20" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="10" height="20" valign="middle"><img src="skin/latest/img/img/bar.gif" width="2" height="12" BORDER="0"></td>
<td width="135" height="20" valign="middle">
<span style=font-size:8pt;><a href='$g4[bbs_path]/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}'>{$list[$i][subject]}</a></span></font></td>
</tr>
</table>
<td width="135" height="20" align="center" class="sub">
<table width="135" height="20" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="10" height="20" valign="middle"><img src="skin/latest/img/img/bar.gif" width="2" height="12" BORDER="0"></td>
<td width="135" height="20" valign="middle">
<span style=font-size:8pt;><a href='$g4[bbs_path]/board.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}'>{$list[$i][subject]}</a></span></font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
HEREDOC;
}
?>
</tr>
</table>
</tr>
</table>
</td>
HEREDOC;
}
?>
</tr>
</table>
</td></tr>
</table>
</table>
댓글 전체
if (file_exists($thumb)) <---------------------------- 이펑션으로는 디렉토리만 나와도 통과합니다.
{
if (!is_dir($thumb)) <----------------------------- 이 펑션으로 확인해야 할듯합니다.
$img = "<img src='$thumb' border=0>";
else
$img = "<img src='$latest_skin_path/img/no_image.gif' border=0 title='이미지 없음'>";
}
{
if (!is_dir($thumb)) <----------------------------- 이 펑션으로 확인해야 할듯합니다.
$img = "<img src='$thumb' border=0>";
else
$img = "<img src='$latest_skin_path/img/no_image.gif' border=0 title='이미지 없음'>";
}
김범식님 답변 정말 감사합니다.
덕분에 깜끔하게 해결하였습니다.
덕분에 깜끔하게 해결하였습니다.