wr_link1을 이용하여 외부이미지 서버로 저장하기 > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

wr_link1을 이용하여 외부이미지 서버로 저장하기 정보

wr_link1을 이용하여 외부이미지 서버로 저장하기

첨부파일

list.skin.php (10.6K) 79회 다운로드 2012-01-17 14:33:09

본문

대부분 갤러리 스킨에서 파일업로드를 사용하여 리스트에 썸네일을 표시하도록 제작되어있습니다.

이 소스는 링크에 외부 이미지를 입력하여 서버로 저장하여 리스트에 표시합니다.

php를 모르시는 분은 이해하기 힘드실 수 있습니다. 소스 내용중 굵게표시된 부분이 링크를 불러와서 서버로 저장하는 부분입니다~ 유용하게 사용하세요~

*첨부파일은 적용 샘플입니다.

$img_width = $board[bo_1];
$img_height = $board[bo_2];
$img_quality = $board[bo_3];
$mod = $board[bo_gallery_cols]; 

if (!$board[bo_1])
$img_width = 120; // 이미지의 폭
if (!$board[bo_2])
$img_height = 88; // 이미지의 높이
if (!$board[bo_3])
$img_quality = 100; // 이미지의 질(quality)
if (!$board[bo_gallery_cols])
$mod = 4; // 가로 이미지 개수

$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';

@mkdir($thumb_path, 0707);
@chmod($thumb_path, 0707);

$img = "<img src='$board_skin_path/img/noimage.gif'  style='border:1px solid #F0F0F0;' border=0 width='$img_width' height='$img_height' alt='이미지 없음'>";

    $thumb = $thumb_path.'/'.$list[$i][wr_id];
$file = '';
if (!file_exists($thumb)) // thumb 이미지 여부
    {
    if($list[$i]['wr_link1']) {
$imageurl = $list[$i]['wr_link1'];
$img_name = basename($imageurl);
$savefile = $data_path . '/' . $img_name;
$file = $savefile;
if(!file_exists($savefile)) {
$ch = curl_init ($imageurl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); 
$rawdata=curl_exec($ch); 
curl_close ($ch);
$fp = fopen($savefile,'w'); 
fwrite($fp, $rawdata); 
fclose($fp); 
}
   } else {
    if($list[$i][file][0][file]) $file = $list[$i][file][0][path] .'/'. $list[$i][file][0][file];
        }
        /* if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file)) */
        if (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 = $img_width / $size[0];
            $height = (int)($size[1] * $rate);


            if ($height < $img_height)
                $dst = imagecreatetruecolor($img_width, $height);
            else
                $dst = imagecreatetruecolor($img_width, $img_height);
            imagecopyresampled($dst, $src, 0, 0, 0, 0, $img_width, $height, $size[0], $size[1]);
//imagepng($dst, $thumb_path.'/'.$list[$i][wr_id], $img_quality);
imagejpeg($dst, $thumb_path.'/'.$list[$i][wr_id], $img_quality);
            chmod($thumb_path.'/'.$list[$i][wr_id], 0606);
        }
    }

    if (file_exists($thumb))
        $img = "<img src='$thumb' width='130' height='90' border=0 style='border:1px solid #F0F0F0;' alt='{$list[$i]['wr_subject']}' />";

추천
4
  • 복사

댓글 5개

© SIRSOFT
현재 페이지 제일 처음으로