데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 130 | 20년 전 | 3981 | ||
| 129 | 20년 전 | 2921 | ||
| 128 | 20년 전 | 3658 | ||
| 127 | 20년 전 | 3482 | ||
| 126 | 20년 전 | 3746 | ||
| 125 | 20년 전 | 8576 | ||
| 124 | 20년 전 | 2596 | ||
| 123 | 20년 전 | 3737 | ||
| 122 | 20년 전 | 3199 | ||
| 121 | 20년 전 | 2602 | ||
| 120 | 20년 전 | 2660 | ||
| 119 | 20년 전 | 2574 | ||
| 118 | 20년 전 | 2858 | ||
| 117 |
|
20년 전 | 3047 | |
| 116 | 20년 전 | 5296 | ||
| 115 | 20년 전 | 3909 | ||
| 114 | 20년 전 | 4957 | ||
| 113 | 20년 전 | 6206 | ||
| 112 | 20년 전 | 7319 | ||
| 111 | 20년 전 | 18426 | ||
| 110 | 20년 전 | 6870 | ||
| 109 | 20년 전 | 2869 | ||
| 108 | 20년 전 | 4136 | ||
| 107 |
prosper
|
20년 전 | 2485 | |
| 106 |
prosper
|
20년 전 | 4310 | |
| 105 |
아우겐나이스
|
20년 전 | 2904 | |
| 104 | 20년 전 | 2255 | ||
| 103 | 20년 전 | 2471 | ||
| 102 | 20년 전 | 2238 | ||
| 101 | 20년 전 | 2565 | ||
| 100 | 20년 전 | 1740 | ||
| 99 | 20년 전 | 1562 | ||
| 98 | 20년 전 | 1614 | ||
| 97 | 20년 전 | 2121 | ||
| 96 | 20년 전 | 1868 | ||
| 95 | 20년 전 | 2367 | ||
| 94 | 20년 전 | 3556 | ||
| 93 | 20년 전 | 1555 | ||
| 92 | 20년 전 | 1748 | ||
| 91 | 20년 전 | 3172 | ||
| 90 | 20년 전 | 2336 | ||
| 89 | 20년 전 | 3162 | ||
| 88 | 20년 전 | 2866 | ||
| 87 | 20년 전 | 3290 | ||
| 86 | 20년 전 | 5120 | ||
| 85 | 20년 전 | 2513 | ||
| 84 | 20년 전 | 4820 | ||
| 83 | 20년 전 | 2498 | ||
| 82 | 20년 전 | 3115 | ||
| 81 | 20년 전 | 7617 | ||
| 80 | 20년 전 | 3816 | ||
| 79 | 20년 전 | 3202 | ||
| 78 | 20년 전 | 4687 | ||
| 77 | 20년 전 | 2891 | ||
| 76 | 20년 전 | 6209 | ||
| 75 | 20년 전 | 4470 | ||
| 74 | 20년 전 | 5774 | ||
| 73 | 20년 전 | 3619 | ||
| 72 | 20년 전 | 5961 | ||
| 71 | 20년 전 | 3104 | ||
| 70 | 20년 전 | 2831 | ||
| 69 | 20년 전 | 2631 | ||
| 68 | 20년 전 | 2441 | ||
| 67 | 20년 전 | 2644 | ||
| 66 | 20년 전 | 2662 | ||
| 65 | 20년 전 | 3783 | ||
| 64 | 20년 전 | 2819 | ||
| 63 | 20년 전 | 2450 | ||
| 62 | 20년 전 | 2257 | ||
| 61 | 20년 전 | 3062 | ||
| 60 | 20년 전 | 3129 | ||
| 59 | 20년 전 | 2505 | ||
| 58 | 20년 전 | 2586 | ||
| 57 | 20년 전 | 2959 | ||
| 56 | 20년 전 | 2310 | ||
| 55 | 20년 전 | 2752 | ||
| 54 | 20년 전 | 2119 | ||
| 53 | 20년 전 | 2344 | ||
| 52 | 20년 전 | 2689 | ||
| 51 |
prosper
|
20년 전 | 2341 | |
| 50 |
prosper
|
20년 전 | 2160 | |
| 49 | 21년 전 | 2172 | ||
| 48 | 21년 전 | 2324 | ||
| 47 | 21년 전 | 1924 | ||
| 46 | 21년 전 | 1920 | ||
| 45 | 21년 전 | 2130 | ||
| 44 | 21년 전 | 2353 | ||
| 43 | 21년 전 | 4568 | ||
| 42 |
prosper
|
21년 전 | 2709 | |
| 41 |
prosper
|
21년 전 | 2109 | |
| 40 | 21년 전 | 2174 | ||
| 39 | 21년 전 | 2138 | ||
| 38 | 21년 전 | 2414 | ||
| 37 | 21년 전 | 2556 | ||
| 36 | 21년 전 | 1768 | ||
| 35 | 21년 전 | 4067 | ||
| 34 | 21년 전 | 3844 | ||
| 33 | 21년 전 | 2985 | ||
| 32 |
prosper
|
21년 전 | 2895 | |
| 31 | 21년 전 | 5266 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기