데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7130 | 11년 전 | 2295 | ||
| 7129 | 11년 전 | 699 | ||
| 7128 |
senseme
|
11년 전 | 1270 | |
| 7127 | 11년 전 | 1146 | ||
| 7126 | 11년 전 | 797 | ||
| 7125 | 11년 전 | 2936 | ||
| 7124 | 11년 전 | 1411 | ||
| 7123 |
잘살아보자
|
11년 전 | 1270 | |
| 7122 |
잘살아보자
|
11년 전 | 666 | |
| 7121 |
잘살아보자
|
11년 전 | 3001 | |
| 7120 |
잘살아보자
|
11년 전 | 2892 | |
| 7119 |
잘살아보자
|
11년 전 | 718 | |
| 7118 |
잘살아보자
|
11년 전 | 3420 | |
| 7117 |
잘살아보자
|
11년 전 | 840 | |
| 7116 | 11년 전 | 725 | ||
| 7115 | 11년 전 | 1012 | ||
| 7114 | 11년 전 | 821 | ||
| 7113 | 11년 전 | 637 | ||
| 7112 | 11년 전 | 1059 | ||
| 7111 | 11년 전 | 1778 | ||
| 7110 | 11년 전 | 1017 | ||
| 7109 |
버섯먹은나
|
11년 전 | 777 | |
| 7108 | 11년 전 | 613 | ||
| 7107 | 11년 전 | 2389 | ||
| 7106 | 11년 전 | 1941 | ||
| 7105 | 11년 전 | 2474 | ||
| 7104 | 11년 전 | 1403 | ||
| 7103 |
|
11년 전 | 2679 | |
| 7102 | 11년 전 | 3101 | ||
| 7101 | 11년 전 | 4427 | ||
| 7100 | 11년 전 | 5779 | ||
| 7099 | 11년 전 | 2122 | ||
| 7098 | 11년 전 | 1701 | ||
| 7097 | 11년 전 | 1437 | ||
| 7096 | 11년 전 | 1110 | ||
| 7095 |
잘살아보자
|
11년 전 | 849 | |
| 7094 |
잘살아보자
|
11년 전 | 1037 | |
| 7093 |
잘살아보자
|
11년 전 | 913 | |
| 7092 |
잘살아보자
|
11년 전 | 1401 | |
| 7091 |
잘살아보자
|
11년 전 | 2194 | |
| 7090 |
잘살아보자
|
11년 전 | 867 | |
| 7089 | 11년 전 | 1046 | ||
| 7088 | 11년 전 | 1700 | ||
| 7087 | 11년 전 | 1394 | ||
| 7086 | 11년 전 | 1286 | ||
| 7085 |
|
11년 전 | 1214 | |
| 7084 | 11년 전 | 1133 | ||
| 7083 | 11년 전 | 3482 | ||
| 7082 | 11년 전 | 1125 | ||
| 7081 | 11년 전 | 1727 | ||
| 7080 | 11년 전 | 2003 | ||
| 7079 | 11년 전 | 1304 | ||
| 7078 | 11년 전 | 1287 | ||
| 7077 | 11년 전 | 1281 | ||
| 7076 | 11년 전 | 744 | ||
| 7075 | 11년 전 | 1143 | ||
| 7074 |
네이비칼라
|
11년 전 | 1490 | |
| 7073 | 11년 전 | 1458 | ||
| 7072 |
|
11년 전 | 822 | |
| 7071 | 11년 전 | 1172 | ||
| 7070 | 11년 전 | 926 | ||
| 7069 | 11년 전 | 1682 | ||
| 7068 | 11년 전 | 1330 | ||
| 7067 |
TPSint
|
11년 전 | 709 | |
| 7066 | 11년 전 | 2139 | ||
| 7065 | 11년 전 | 6625 | ||
| 7064 | 11년 전 | 1280 | ||
| 7063 | 11년 전 | 1126 | ||
| 7062 | 11년 전 | 1059 | ||
| 7061 | 11년 전 | 899 | ||
| 7060 | 11년 전 | 1436 | ||
| 7059 | 11년 전 | 841 | ||
| 7058 |
EngineMan
|
11년 전 | 3386 | |
| 7057 | 11년 전 | 1234 | ||
| 7056 | 11년 전 | 1629 | ||
| 7055 | 11년 전 | 999 | ||
| 7054 | 11년 전 | 2638 | ||
| 7053 |
네이비칼라
|
11년 전 | 1273 | |
| 7052 | 11년 전 | 2559 | ||
| 7051 | 11년 전 | 1924 | ||
| 7050 | 11년 전 | 2442 | ||
| 7049 | 11년 전 | 1384 | ||
| 7048 | 11년 전 | 2514 | ||
| 7047 | 11년 전 | 1331 | ||
| 7046 | 11년 전 | 1016 | ||
| 7045 | 11년 전 | 1040 | ||
| 7044 | 11년 전 | 5427 | ||
| 7043 | 11년 전 | 1213 | ||
| 7042 | 11년 전 | 773 | ||
| 7041 |
열라뽕똬이
|
11년 전 | 746 | |
| 7040 | 11년 전 | 1096 | ||
| 7039 | 11년 전 | 1446 | ||
| 7038 | 11년 전 | 1859 | ||
| 7037 | 11년 전 | 2165 | ||
| 7036 | 11년 전 | 1079 | ||
| 7035 | 11년 전 | 1398 | ||
| 7034 | 11년 전 | 1337 | ||
| 7033 |
열라뽕똬이
|
11년 전 | 986 | |
| 7032 | 11년 전 | 747 | ||
| 7031 | 11년 전 | 2172 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기