데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7330 | 11년 전 | 1674 | ||
| 7329 | 11년 전 | 931 | ||
| 7328 | 11년 전 | 2221 | ||
| 7327 | 11년 전 | 1721 | ||
| 7326 | 11년 전 | 3806 | ||
| 7325 | 11년 전 | 2262 | ||
| 7324 | 11년 전 | 4509 | ||
| 7323 |
호식이와미돌
|
11년 전 | 1279 | |
| 7322 |
호식이와미돌
|
11년 전 | 1139 | |
| 7321 | 11년 전 | 1784 | ||
| 7320 | 11년 전 | 1755 | ||
| 7319 | 11년 전 | 1314 | ||
| 7318 |
|
11년 전 | 967 | |
| 7317 |
멋진남자임
|
11년 전 | 1615 | |
| 7316 |
잘살아보자
|
11년 전 | 985 | |
| 7315 | 11년 전 | 1092 | ||
| 7314 | 11년 전 | 1313 | ||
| 7313 |
잘살아보자
|
11년 전 | 1119 | |
| 7312 | 11년 전 | 875 | ||
| 7311 |
사랑한데이
|
11년 전 | 2059 | |
| 7310 |
잘살아보자
|
11년 전 | 1874 | |
| 7309 |
잘살아보자
|
11년 전 | 3042 | |
| 7308 |
잘살아보자
|
11년 전 | 1015 | |
| 7307 |
잘살아보자
|
11년 전 | 781 | |
| 7306 | 11년 전 | 866 | ||
| 7305 |
잘살아보자
|
11년 전 | 2754 | |
| 7304 | 11년 전 | 1017 | ||
| 7303 | 11년 전 | 1216 | ||
| 7302 | 11년 전 | 724 | ||
| 7301 | 11년 전 | 1509 | ||
| 7300 |
mijaya
|
11년 전 | 1491 | |
| 7299 | 11년 전 | 905 | ||
| 7298 | 11년 전 | 1089 | ||
| 7297 | 11년 전 | 764 | ||
| 7296 | 11년 전 | 724 | ||
| 7295 | 11년 전 | 1551 | ||
| 7294 | 11년 전 | 900 | ||
| 7293 | 11년 전 | 804 | ||
| 7292 | 11년 전 | 909 | ||
| 7291 |
잘살아보자
|
11년 전 | 1092 | |
| 7290 |
잘살아보자
|
11년 전 | 738 | |
| 7289 | 11년 전 | 787 | ||
| 7288 |
잘살아보자
|
11년 전 | 1304 | |
| 7287 | 11년 전 | 825 | ||
| 7286 |
잘살아보자
|
11년 전 | 1323 | |
| 7285 | 11년 전 | 817 | ||
| 7284 | 11년 전 | 981 | ||
| 7283 | 11년 전 | 1007 | ||
| 7282 | 11년 전 | 766 | ||
| 7281 | 11년 전 | 794 | ||
| 7280 | 11년 전 | 1027 | ||
| 7279 | 11년 전 | 1960 | ||
| 7278 | 11년 전 | 797 | ||
| 7277 | 11년 전 | 808 | ||
| 7276 | 11년 전 | 746 | ||
| 7275 | 11년 전 | 1164 | ||
| 7274 | 11년 전 | 808 | ||
| 7273 | 11년 전 | 717 | ||
| 7272 | 11년 전 | 1047 | ||
| 7271 | 11년 전 | 1377 | ||
| 7270 | 11년 전 | 1003 | ||
| 7269 | 11년 전 | 927 | ||
| 7268 | 11년 전 | 977 | ||
| 7267 | 11년 전 | 1806 | ||
| 7266 | 11년 전 | 874 | ||
| 7265 | 11년 전 | 929 | ||
| 7264 |
잘살아보자
|
11년 전 | 2711 | |
| 7263 |
잘살아보자
|
11년 전 | 2254 | |
| 7262 |
잘살아보자
|
11년 전 | 1139 | |
| 7261 |
잘살아보자
|
11년 전 | 1631 | |
| 7260 |
잘살아보자
|
11년 전 | 1244 | |
| 7259 | 11년 전 | 1160 | ||
| 7258 |
잘살아보자
|
11년 전 | 1292 | |
| 7257 |
잘살아보자
|
11년 전 | 1893 | |
| 7256 | 11년 전 | 931 | ||
| 7255 |
그누5입문
|
11년 전 | 1941 | |
| 7254 | 11년 전 | 2162 | ||
| 7253 |
|
11년 전 | 861 | |
| 7252 | 11년 전 | 1005 | ||
| 7251 | 11년 전 | 714 | ||
| 7250 | 11년 전 | 1679 | ||
| 7249 | 11년 전 | 1545 | ||
| 7248 |
sogo87
|
11년 전 | 1033 | |
| 7247 | 11년 전 | 923 | ||
| 7246 | 11년 전 | 698 | ||
| 7245 |
잘살아보자
|
11년 전 | 1071 | |
| 7244 | 11년 전 | 1524 | ||
| 7243 |
presee
|
11년 전 | 592 | |
| 7242 |
sogo87
|
11년 전 | 781 | |
| 7241 | 11년 전 | 866 | ||
| 7240 |
브라이언2
|
11년 전 | 884 | |
| 7239 |
|
11년 전 | 1088 | |
| 7238 | 11년 전 | 2616 | ||
| 7237 |
잘살아보자
|
11년 전 | 2275 | |
| 7236 |
dethos79
|
11년 전 | 1839 | |
| 7235 |
멋진남자임
|
11년 전 | 1403 | |
| 7234 | 11년 전 | 1341 | ||
| 7233 | 11년 전 | 2313 | ||
| 7232 | 11년 전 | 1581 | ||
| 7231 | 11년 전 | 2780 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기