채택완료

상품이미지 첨부 안하면 특정 이미지 보여지게

2025-10-06 (월) 07:23:45 575

안녕하세요.

그누보드로 쇼핑몰을 만들었는데요.

상품이미지를 하나도 첨부 안하면, A라는 이미지(서버에 업로드된 이미지)가 기본값으로 보여지게 하고 싶습니다.

혹시 어디를 수정해야 할지 위치라도 알려주시면 정말 감사하겠습니다..

|

답변 2개

채택된 답변
+20 포인트
2025-10-06 (월) 12:35:15

/theme/basic/skin/shop/basic/item.form.skin.php
설정된 테마의

Copy
<?php
            $big_img_count = 0;
            $thumbnails = array();
            for($i=1; $i<=10; $i++) {
                if(!$it['it_img'.$i])
                    continue;
    
                $img = get_it_thumbnail($it['it_img'.$i], $default['de_mimg_width'], $default['de_mimg_height']);
    
                if($img) {
                    // 썸네일
                    $thumb = get_it_thumbnail($it['it_img'.$i], 70, 70);
                    $thumbnails[] = $thumb;
                    $big_img_count++;
    
                    echo '<a href="'.G5_SHOP_URL.'/largeimage.php?it_id='.$it['it_id'].'&amp;no='.$i.'" target="_blank" class="popup_item_image">'.$img.'</a>';
                }
            }
    
            if($big_img_count == 0) {
                echo '<img src="'.G5_SHOP_URL.'/img/no_image.gif" alt="">';
            }
            ?>


목록에서는 
/theme/basic/skin/shop/basic/list.10.skin.php
    if ($this->view_it_img) {
        echo get_it_image($row['it_id'], $this->img_width, $this->img_height, '', '', stripslashes($row['it_name']))."\n";
    }

이 부분에 이미지 가져오는 부분이 있습니다.
/lib/shop.lib.php
get_it_image() 에 정의 되어 있습니다.

Copy
// 상품 이미지를 얻는다
function get_it_image($it_id, $width, $height=0, $anchor=false, $img_id='', $img_alt='', $is_crop=false)
{
    global $g5;

    if(!$it_id || !$width)
        return '';

    $row = get_shop_item($it_id, true);

    if(!$row['it_id'])
        return '';

    $filename = $thumb = $img = '';
    
    $img_width = 0;
    for($i=1;$i<=10; $i++) {
        $file = G5_DATA_PATH.'/item/'.$row['it_img'.$i];
        if(is_file($file) && $row['it_img'.$i]) {
            $size = @getimagesize($file);
            if(! isset($size[2]) || $size[2] < 1 || $size[2] > 3)
                continue;

            $filename = basename($file);
            $filepath = dirname($file);
            $img_width = $size[0];
            $img_height = $size[1];

            break;
        }
    }

    if($img_width && !$height) {
        $height = round(($width * $img_height) / $img_width);
    }

    if($filename) {
        //thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height, $is_create, $is_crop=false, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')
        $thumb = thumbnail($filename, $filepath, $filepath, $width, $height, false, $is_crop, 'center', false, $um_value='80/0.5/3');
    }

    if($thumb) {
        $file_url = str_replace(G5_PATH, G5_URL, $filepath.'/'.$thumb);
        $img = '<img src="'.$file_url.'" width="'.$width.'" height="'.$height.'" alt="'.$img_alt.'"';
    } else {
        $img = '<img src="'.G5_SHOP_URL.'/img/no_image.gif" width="'.$width.'"';
        if($height)
            $img .= ' height="'.$height.'"';
        $img .= ' alt="'.$img_alt.'"';
    }

    if($img_id)
        $img .= ' id="'.$img_id.'"';
    $img .= '>';

    if($anchor)
        $img = $img = '<a href="'.shop_item_url($it_id).'">'.$img.'</a>';

    return run_replace('get_it_image_tag', $img, $thumb, $it_id, $width, $height, $anchor, $img_id, $img_alt, $is_crop);
}

위의 내용을 참고하면 쉽게 구현할 수 있을 것입니다.
2025-10-06 (월) 09:06:43

shop/img/no_image.gif 

기본 노이이지  파일 교체하시면됩니다.

만약 다른 이미지형식으로 바꾸고자한다면 shop/item.php 파일열어서 파일명 수정해주시면됩니다.

답변을 작성하려면 로그인이 필요합니다.