다중 이미지 갤러리 - view에서 이미지가 없을 때 noimage.gif 출력 > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

다중 이미지 갤러리 - view에서 이미지가 없을 때 noimage.gif 출력 정보

다중 이미지 갤러리 - view에서 이미지가 없을 때 noimage.gif 출력

본문

[갤러리] 다중 이미지 갤러리-가로형을 수정중인데
첨부 된 이미지 파일이 없을 때 "noimage.gif"가 출력되게 하려고 소스를
수정해 보다가 안되서 질문 남깁니다..


---// view.skin.php 내용//--------------------------

//================== 윗 부분 생략

<SCRIPT LANGUAGE="JavaScript">
<!--
image_directory = "";   //배경이미지 경로
clear = new Image();  clear.src = image_directory + "./img/blank.gif";
<?
//파일 뽑기
$sql2 = " select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no limit 0, 5 ";
$result2 = sql_query($sql2);
//for ($j=0; $row2 = sql_fetch_array($result2); $j++) {
//$view_one = "{$g4['path']}/data/file/{$bo_table}/{$row2['bf_file']}";
for ($j=0; $row2 = sql_fetch_array($result2); $j++) {
if($j==0) {
$view_one = "{$g4['path']}/data/file/{$bo_table}/{$row2['bf_file']}";
}

?>
view_img<?=$j?> = new Image();
view_img<?=$j?>.src = "<?=$g4['path']?>/data/file/<?=$bo_table?>/<?=$row2['bf_file']?>";
<? } ?>
function bgChange(imgName) {
    document.all.view_img.src = eval(imgName + ".src");
}
//  -->
</SCRIPT>

<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
    <tr>
        <td width="10"></td>
        <td bgcolor="#f1f1f1" style="padding:0 0 0 0px;" width="290" height="240" align="center" valign="top">
        <div style='width:290px; height:240px; position:relative; overflow:hidden;' align=center><img src="<?=$view_one?>" name="view_img" width="290" border="0" alt=""></a></div>
<!-- <?=$view_one?>이 이미지가 출력되는 곳이고, 질문을 드리는 내용입니다. -->
        </td>
        <td width="10"></td>
    </tr>
    <tr>
        <td width="10"></td>
        <td bgcolor="#f1f1f1" style="padding:10 0 10 0px;" width="290" height="60" align="center" valign="top">

<script language="JavaScript">
<!--
function OpenWin(url,intWidth,intHeight){
      window.open(url, "ReadSlideShow", "scrollbars=no, resizable=no, width="+intWidth+",height="+intHeight+" ");
      return;
}
//-->
</script>

<script>
  function chgImg( imgname, dnimgname, imgdesc) {
    var LureExp = /<br>/gi;
    document.gallery_img.src=imgname;
      }
</script>

//================== 중간 테이블 생략

<?
//파일 뽑기
$sql = " select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no limit 0, 5 ";
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++) {

//썸네일 코드 시작
$data_path = $g4['path'] . "/data/file/{$bo_table}";//라이브러리 파일 참조
$thumb_path = $data_path . '/thumbopen';

$view_w = 50; //썸네일 가로사이즈
$view_h = 40; //썸네일 세로사이즈
$sch_q = 90; //썸네일 퀼리티

if (!is_dir($thumb_path)) {
@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);
}
    $filename = $row[bf_file]; //파일명
    $thumb = $thumb_path.'/'.$filename; //썸네일
    if (!file_exists($thumb))
    {
    $file = $data_path.'/'.$filename; //원본
        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 = $view_w / $size[0];
            $height = (int)($size[1] * $rate);

            // 계산된 썸네일 이미지의 높이가 설정된 이미지의 높이보다 작다면
            if ($height < $view_h)
                // 계산된 이미지 높이로 복사본 이미지 생성
                $dst = imagecreatetruecolor($view_w, $height);
            else
                // 설정된 이미지 높이로 복사본 이미지 생성
                $dst = imagecreatetruecolor($view_w, $view_h);

            imagecopyresampled($dst, $src, 0, 0, 0, 0, $view_w, $height, $size[0], $size[1]);
            imagejpeg($dst, $thumb_path.'/'.$filename, $sch_q);
            chmod($thumb_path.'/'.$filename, 0707);
        }
    }

    if (file_exists($thumb) && $filename)
        $thumfile = "<img src='{$thumb}' alt='{$img_subject}'>";
        else
        //이미지가 없으면
        $thumfile="<img src=$board_skin_path/images/noimage.gif alt='이미지가 없습니다'>";
        //이미지가 없습니다.
        if(preg_match("/\.(swf|wma|asf)$/i","$file") && file_exists($file)){
        $thumfile = "<script>doc_write(flash_movie('$file', 'flash$i', '$thumb_width', '$thumb_height', 'transparent'));</script>";
        }
       
        {

//    if (file_exists($thumb) && $filename) {
?>
<a href="javascript:void(0);" onClick="View_Open('<?=$data_path?>/<?=$filename?>')" onMouseOver="bgChange('view_img<?=$i?>');" onMouseOut="bgChange('view_img<?=$i?>');"><img src='<?=$thumb?>' border="0" alt="원본이미지 보기 클릭"></a>

<?
//onMouseOut="bgChange('clear');"
}
}
?>
        </td>
        <td width="10"></td>
    </tr>
        <tr>
            <td colspan="3" valign="top" width="100%" height="25" align="center" valign="bottom">
            <a href='#' onclick="javascript:window.open('<?=$board_skin_path?>/view_open.php?bo_table=<?=$bo_table?>&wr_id=<?=$wr_id?>','view_open','width=800,height=560,top=50,left=50,scrollbars=yes,resizable=yes')"><img src="<?=$board_skin_path?>/images/icon_open.gif" border="0" width="100" height="20" alt="원본사이즈로 이미지 보기"></a></td>
        </tr>
</table>
//===============  여기까지


  • 복사

댓글 전체

//이미지가 없으면
        $thumfile="<img src=$board_skin_path/images/noimage3.gif alt='이미지가 없습니다'>";
        //이미지가 없습니다.

이부분아닌가요
보드스킨 images 안에 noimage3.gif 넣어보셔요
네, noimage3.gif 와 noimage.gif 는 같은 겁니다. 질문 내용 중 "noimage3.gif" -> "noimage.gif"로 수정했습니다.

자세히 말씀드리면, 소스 중 윗 부분에 있는

======================================================

<?
//파일 뽑기

$sql2 = " select bf_file from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no limit 0, 5 ";
$result2 = sql_query($sql2);
//for ($j=0; $row2 = sql_fetch_array($result2); $j++) {
//$view_one = "{$g4['path']}/data/file/{$bo_table}/{$row2['bf_file']}";
for ($j=0; $row2 = sql_fetch_array($result2); $j++) {
if($j==0) {
$view_one = "{$g4['path']}/data/file/{$bo_table}/{$row2['bf_file']}";
}
?>


<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
<tr>
<td width="10"></td>
<td bgcolor="#f1f1f1" style="padding:0 0 0 0px;" width="290" height="240" align="center" valign="top">
<div style='width:290px; height:240px; position:relative; overflow:hidden;' align=center><img src="<?=$view_one?>" name="view_img" width="290" border="0" alt=""></a></div>
</td>
<td width="10"></td>
</tr>
<tr>
<td width="10"></td>
<td bgcolor="#f1f1f1" style="padding:10 0 10 0px;" width="290" height="60" align="center" valign="top">

======================================================

이 내용 중 <img src="<?=$view_one?>" name="view_img" width="290" border="0" alt=""> 에서
출력이 되는데, $view_one에 출력 될 파일이 없으면 "noimage.gif"가 나오게 하는 것입니다. ㅜㅜ
if(!file_exist($view_one)) $view_one = "noimage.gif"; 응용해보세요

<img src="<?=$view_one?>" name="view_img" width="290" border="0" alt=""> 위에
<? if(!file_exist($view_one)) $view_one = "noimage.gif"; ?> 를 추가해보시길
© SIRSOFT
현재 페이지 제일 처음으로