데모
<?php
//ver1.0 150409 @_untitle_d
function save_remote_image($url, $save_path)
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0); // required
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // required for images
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // maybe redirect on other side?
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'); // or user agent checks?
$data=curl_exec($ch);
curl_close ($ch);
$chars_array = array_merge(range(0,9), range('a','z'), range('A','Z'));
//아래의 문자열이 들어간 파일은 -x 를 붙여서 웹경로를 알더라도 실행을 하지 못하도록 함
$filename = preg_replace("/\.(php|phtm|htm|cgi|pl|exe|jsp|asp|inc)/i", "$0-x", basename($url));
shuffle($chars_array);
$shuffle = implode("", $chars_array);
//첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)
$change_filename = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr($shuffle,0,8).'_'.str_replace('%', '', urlencode(str_replace(' ', '_', $filename)));
$out_path = $save_path.$change_filename;
if(file_exists($out_path)) @unlink($out_path);
$fp = fopen($out_path,'x');
fwrite($fp, $data);
fclose($fp);
return $change_filename;
}
$url = 'http://i.imgur.com/OJws8NX.png'; //외부이미지
$save_path = $_SERVER[DOCUMENT_ROOT].'/data/remote/'; 타겟폴더
$remote_image = 'http://'.$_SERVER[SERVER_NAME].'/data/remote/'.save_remote_image($url, $save_path);
?>
<img src="<?=$remote_image?>"><br>
<?=$remote_image?>
관련링크
http://untitled.untitle311apyxry1w48.com/pjtecuh
참고
http://stackoverflow.com/questions/7375021/php-retrieve-and-save-remote-image
http://phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_function&wr_id=292925
댓글 1개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 43 | ||
| 8229 | 9년 전 | 51 | ||
| 8228 |
커네드커네드
|
9년 전 | 94 | |
| 8227 | 9년 전 | 104 | ||
| 8226 | 9년 전 | 141 | ||
| 8225 | 9년 전 | 132 | ||
| 8224 | 9년 전 | 128 | ||
| 8223 | 9년 전 | 87 | ||
| 8222 |
|
9년 전 | 161 | |
| 8221 | 9년 전 | 77 | ||
| 8220 | 9년 전 | 71 | ||
| 8219 | 9년 전 | 76 | ||
| 8218 | 9년 전 | 111 | ||
| 8217 |
star3840
|
9년 전 | 95 | |
| 8216 | 9년 전 | 131 | ||
| 8215 | 9년 전 | 84 | ||
| 8214 | 9년 전 | 202 | ||
| 8213 | 9년 전 | 141 | ||
| 8212 | 9년 전 | 54 | ||
| 8211 | 9년 전 | 220 | ||
| 8210 | 9년 전 | 213 | ||
| 8209 | 9년 전 | 315 | ||
| 8208 | 9년 전 | 184 | ||
| 8207 | 9년 전 | 197 | ||
| 8206 |
|
9년 전 | 159 | |
| 8205 | 9년 전 | 144 | ||
| 8204 | 9년 전 | 107 | ||
| 8203 | 9년 전 | 198 | ||
| 8202 | 9년 전 | 123 | ||
| 8201 | 9년 전 | 162 | ||
| 8200 | 9년 전 | 133 | ||
| 8199 | 9년 전 | 178 | ||
| 8198 | 9년 전 | 152 | ||
| 8197 | 9년 전 | 132 | ||
| 8196 | 9년 전 | 511 | ||
| 8195 | 9년 전 | 133 | ||
| 8194 | 9년 전 | 265 | ||
| 8193 | 9년 전 | 131 | ||
| 8192 | 9년 전 | 160 | ||
| 8191 | 9년 전 | 115 | ||
| 8190 | 9년 전 | 108 | ||
| 8189 | 9년 전 | 163 | ||
| 8188 | 9년 전 | 105 | ||
| 8187 | 9년 전 | 119 | ||
| 8186 | 9년 전 | 128 | ||
| 8185 | 9년 전 | 291 | ||
| 8184 | 9년 전 | 82 | ||
| 8183 | 9년 전 | 306 | ||
| 8182 | 9년 전 | 137 | ||
| 8181 | 9년 전 | 110 | ||
| 8180 | 9년 전 | 677 | ||
| 8179 | 9년 전 | 471 | ||
| 8178 | 9년 전 | 276 | ||
| 8177 |
kiplayer
|
9년 전 | 283 | |
| 8176 | 9년 전 | 324 | ||
| 8175 | 9년 전 | 203 | ||
| 8174 | 9년 전 | 210 | ||
| 8173 | 9년 전 | 321 | ||
| 8172 | 9년 전 | 164 | ||
| 8171 | 9년 전 | 159 | ||
| 8170 | 9년 전 | 275 | ||
| 8169 |
커네드커네드
|
9년 전 | 243 | |
| 8168 | 9년 전 | 295 | ||
| 8167 | 9년 전 | 303 | ||
| 8166 | 9년 전 | 214 | ||
| 8165 | 9년 전 | 146 | ||
| 8164 | 9년 전 | 276 | ||
| 8163 | 9년 전 | 264 | ||
| 8162 | 9년 전 | 270 | ||
| 8161 | 9년 전 | 269 | ||
| 8160 |
|
9년 전 | 465 | |
| 8159 | 9년 전 | 381 | ||
| 8158 | 9년 전 | 200 | ||
| 8157 | 9년 전 | 339 | ||
| 8156 | 9년 전 | 255 | ||
| 8155 | 9년 전 | 231 | ||
| 8154 |
00년생용띠
|
9년 전 | 576 | |
| 8153 | 9년 전 | 203 | ||
| 8152 |
|
9년 전 | 381 | |
| 8151 | 9년 전 | 382 | ||
| 8150 | 9년 전 | 473 | ||
| 8149 |
Jangfolk
|
9년 전 | 313 | |
| 8148 | 9년 전 | 147 | ||
| 8147 | 9년 전 | 356 | ||
| 8146 | 9년 전 | 409 | ||
| 8145 | 9년 전 | 339 | ||
| 8144 | 9년 전 | 305 | ||
| 8143 | 9년 전 | 161 | ||
| 8142 | 9년 전 | 406 | ||
| 8141 | 9년 전 | 355 | ||
| 8140 | 9년 전 | 904 | ||
| 8139 | 9년 전 | 228 | ||
| 8138 |
전갈자리남자
|
9년 전 | 368 | |
| 8137 | 9년 전 | 349 | ||
| 8136 | 9년 전 | 714 | ||
| 8135 |
|
9년 전 | 763 | |
| 8134 |
PlayPixel
|
9년 전 | 478 | |
| 8133 |
|
9년 전 | 418 | |
| 8132 | 9년 전 | 429 | ||
| 8131 | 9년 전 | 784 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기