wr_link1을 이용하여 외부이미지 서버로 저장하기
대부분 갤러리 스킨에서 파일업로드를 사용하여 리스트에 썸네일을 표시하도록 제작되어있습니다.
이 소스는 링크에 외부 이미지를 입력하여 서버로 저장하여 리스트에 표시합니다.
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']}' />";
댓글 5개
13년 전
혹시 이 내용하고 비슷한건가요?
http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=21620&sca=&sfl=wr_subject||wr_content&stx=%EC%99%B8%EB%B6%80%EC%9D%B4%EB%AF%B8%EC%A7%80&sop=and
추천은 드리고 갑니다.
http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=21620&sca=&sfl=wr_subject||wr_content&stx=%EC%99%B8%EB%B6%80%EC%9D%B4%EB%AF%B8%EC%A7%80&sop=and
추천은 드리고 갑니다.
13년 전
이미지를 서버에 저장말고 썸네임으로도 출력만 할수 없나요?
June44
13년 전
썸네일 자체가 서버에 저장하는 방식입니다..^^;
13년 전
응용좀 해봐야겠네요^^
June44
13년 전
^^ 더 좋은 방법있으시면 변경해주세요~
게시글 목록
| 번호 | 제목 |
|---|---|
| 33565 | |
| 33549 | |
| 33548 | |
| 33500 | |
| 33497 | |
| 33495 | |
| 33484 | |
| 33483 | |
| 33474 | |
| 33465 | |
| 33464 | |
| 33462 | |
| 33461 | |
| 33457 | |
| 33456 | |
| 33441 | |
| 33440 | |
| 33417 | |
| 33416 | |
| 33415 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기