상품의 모든 이미지를 배열로 반환 > 정보공유

본문 바로가기

정보공유

일반글
영카트팁

상품의 모든 이미지를 배열로 반환

페이지 정보

게시물QR코드

본문

영카트의 목록에서는 가장 처음 등록 한 이미지가 대표이미지로 설정됩니다.

간혹 마우스 오버시 두번째 이미지를 보여주게 하고 싶거나 할 경우

아래의 함수를 응용하여 다른 순서의 이미지를 불러 올 수 있습니다.

<?php

// 영카트 상품 이미지 모두 가져오기

function get_it_image_array($it_id, $width, $height=0, $anchor=false, $img_id='', $img_alt='', $is_crop=false){

    global $g5;


    $item_image_array = array();


    if(!$it_id || !$width) {

        return '';

    }


    $sql = " select it_id, it_img1, it_img2, it_img3, it_img4, it_img5, it_img6, it_img7, it_img8, it_img9, it_img10 from {$g5['g5_shop_item_table']} where it_id = '$it_id' ";

    $row = sql_fetch($sql);


    if(!$row['it_id']) {

        return '';

    }


    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($size[2] < 1 || $size[2] > 3) {

                continue;

            }

            $filename = basename($file);

            $filepath = dirname($file);

            $img_width = $size[0];

            $img_height = $size[1];

        }


        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 = '<a href="'.G5_SHOP_URL.'/item.php?it_id='.$it_id.'">'.$img.'</a>';

        }


        $item_image_array[] = $img;

    }


    return $item_image_array;

}


사용방법

<?php

// 사용방법

$item_image_array = get_it_image_array($row['it_id'], $this->img_width, $this->img_height, '', '', stripslashes($row['it_name']));


echo "<div class='flexslider2'>";

echo "<ul class='slides'>";

foreach($item_image_array as $key => $val) {

    echo "<li class='imgLi'>{$val}</li>";

}

echo "</ul>";

echo "</div>";

댓글목록

등록된 댓글이 없습니다.

  • Addr.부산광역시 동구 중앙대로 319, 9층 L4호(초량동, 부산YMCA빌딩) Email. gnuwiz@naver.com
  • BR. 625-68-00172 TRC. 2019-부산해운대-1186 TEL. 0507-1382-2790
All rights reserved.