데모
<?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년 전 | 3969 | ||
| 129 | 20년 전 | 2910 | ||
| 128 | 20년 전 | 3636 | ||
| 127 | 20년 전 | 3433 | ||
| 126 | 20년 전 | 3724 | ||
| 125 | 20년 전 | 8559 | ||
| 124 | 20년 전 | 2584 | ||
| 123 | 20년 전 | 3735 | ||
| 122 | 20년 전 | 3191 | ||
| 121 | 20년 전 | 2589 | ||
| 120 | 20년 전 | 2651 | ||
| 119 | 20년 전 | 2564 | ||
| 118 | 20년 전 | 2850 | ||
| 117 |
|
20년 전 | 3031 | |
| 116 | 20년 전 | 5289 | ||
| 115 | 20년 전 | 3892 | ||
| 114 | 20년 전 | 4942 | ||
| 113 | 20년 전 | 6195 | ||
| 112 | 20년 전 | 7317 | ||
| 111 | 20년 전 | 18419 | ||
| 110 | 20년 전 | 6868 | ||
| 109 | 20년 전 | 2866 | ||
| 108 | 20년 전 | 4125 | ||
| 107 |
prosper
|
20년 전 | 2468 | |
| 106 |
prosper
|
20년 전 | 4294 | |
| 105 |
아우겐나이스
|
20년 전 | 2891 | |
| 104 | 20년 전 | 2246 | ||
| 103 | 20년 전 | 2463 | ||
| 102 | 20년 전 | 2217 | ||
| 101 | 20년 전 | 2549 | ||
| 100 | 20년 전 | 1728 | ||
| 99 | 20년 전 | 1556 | ||
| 98 | 20년 전 | 1606 | ||
| 97 | 20년 전 | 2104 | ||
| 96 | 20년 전 | 1862 | ||
| 95 | 20년 전 | 2356 | ||
| 94 | 20년 전 | 3548 | ||
| 93 | 20년 전 | 1545 | ||
| 92 | 20년 전 | 1739 | ||
| 91 | 20년 전 | 3154 | ||
| 90 | 20년 전 | 2331 | ||
| 89 | 20년 전 | 3156 | ||
| 88 | 20년 전 | 2858 | ||
| 87 | 20년 전 | 3284 | ||
| 86 | 20년 전 | 5103 | ||
| 85 | 20년 전 | 2506 | ||
| 84 | 20년 전 | 4803 | ||
| 83 | 20년 전 | 2483 | ||
| 82 | 20년 전 | 3098 | ||
| 81 | 20년 전 | 7602 | ||
| 80 | 20년 전 | 3806 | ||
| 79 | 20년 전 | 3195 | ||
| 78 | 20년 전 | 4679 | ||
| 77 | 20년 전 | 2883 | ||
| 76 | 20년 전 | 6204 | ||
| 75 | 20년 전 | 4462 | ||
| 74 | 20년 전 | 5769 | ||
| 73 | 20년 전 | 3615 | ||
| 72 | 20년 전 | 5951 | ||
| 71 | 20년 전 | 3094 | ||
| 70 | 20년 전 | 2823 | ||
| 69 | 20년 전 | 2620 | ||
| 68 | 20년 전 | 2427 | ||
| 67 | 20년 전 | 2638 | ||
| 66 | 20년 전 | 2659 | ||
| 65 | 20년 전 | 3778 | ||
| 64 | 20년 전 | 2805 | ||
| 63 | 20년 전 | 2443 | ||
| 62 | 20년 전 | 2246 | ||
| 61 | 20년 전 | 3047 | ||
| 60 | 20년 전 | 3120 | ||
| 59 | 20년 전 | 2493 | ||
| 58 | 20년 전 | 2580 | ||
| 57 | 20년 전 | 2952 | ||
| 56 | 20년 전 | 2300 | ||
| 55 | 20년 전 | 2739 | ||
| 54 | 20년 전 | 2111 | ||
| 53 | 20년 전 | 2336 | ||
| 52 | 20년 전 | 2682 | ||
| 51 |
prosper
|
20년 전 | 2335 | |
| 50 |
prosper
|
20년 전 | 2154 | |
| 49 | 20년 전 | 2160 | ||
| 48 | 20년 전 | 2315 | ||
| 47 | 20년 전 | 1914 | ||
| 46 | 20년 전 | 1916 | ||
| 45 | 20년 전 | 2122 | ||
| 44 | 20년 전 | 2348 | ||
| 43 | 21년 전 | 4563 | ||
| 42 |
prosper
|
21년 전 | 2698 | |
| 41 |
prosper
|
21년 전 | 2100 | |
| 40 | 21년 전 | 2164 | ||
| 39 | 21년 전 | 2131 | ||
| 38 | 21년 전 | 2399 | ||
| 37 | 21년 전 | 2550 | ||
| 36 | 21년 전 | 1766 | ||
| 35 | 21년 전 | 4059 | ||
| 34 | 21년 전 | 3839 | ||
| 33 | 21년 전 | 2978 | ||
| 32 |
prosper
|
21년 전 | 2886 | |
| 31 | 21년 전 | 5251 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기