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년 전
^^ 더 좋은 방법있으시면 변경해주세요~
게시판 목록
그누4 팁자료실
그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3289 | 9년 전 | 4812 | ||
| 3288 | 9년 전 | 5799 | ||
| 3287 |
|
9년 전 | 3504 | |
| 3286 |
또치하우스
|
9년 전 | 12301 | |
| 3285 | 9년 전 | 11500 | ||
| 3284 |
다람쥐7마리
|
10년 전 | 4680 | |
| 3283 |
블랙초콜렛더블샷
|
10년 전 | 5971 | |
| 3282 |
또치하우스
|
10년 전 | 10270 | |
| 3281 | 10년 전 | 9787 | ||
| 3280 | 10년 전 | 4992 | ||
| 3279 | 10년 전 | 4273 | ||
| 3278 | 10년 전 | 5356 | ||
| 3277 |
|
10년 전 | 5266 | |
| 3276 | 10년 전 | 5778 | ||
| 3275 | 10년 전 | 4351 | ||
| 3274 | 10년 전 | 5592 | ||
| 3273 | 10년 전 | 6908 | ||
| 3272 | 10년 전 | 7220 | ||
| 3271 | 10년 전 | 4933 | ||
| 3270 |
|
10년 전 | 5404 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기