데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 230 | 20년 전 | 2094 | ||
| 229 | 20년 전 | 3155 | ||
| 228 | 20년 전 | 3344 | ||
| 227 | 20년 전 | 2419 | ||
| 226 | 20년 전 | 5499 | ||
| 225 | 20년 전 | 2542 | ||
| 224 | 20년 전 | 2985 | ||
| 223 | 20년 전 | 4219 | ||
| 222 | 20년 전 | 2616 | ||
| 221 | 20년 전 | 2305 | ||
| 220 | 20년 전 | 3692 | ||
| 219 | 20년 전 | 2090 | ||
| 218 | 20년 전 | 3588 | ||
| 217 | 20년 전 | 2500 | ||
| 216 | 20년 전 | 2939 | ||
| 215 | 20년 전 | 2249 | ||
| 214 | 20년 전 | 3356 | ||
| 213 | 20년 전 | 2941 | ||
| 212 | 20년 전 | 3085 | ||
| 211 | 20년 전 | 2171 | ||
| 210 | 20년 전 | 1932 | ||
| 209 | 20년 전 | 2383 | ||
| 208 | 20년 전 | 2015 | ||
| 207 | 20년 전 | 1695 | ||
| 206 | 20년 전 | 1869 | ||
| 205 | 20년 전 | 3967 | ||
| 204 | 20년 전 | 1690 | ||
| 203 | 20년 전 | 2032 | ||
| 202 | 20년 전 | 2369 | ||
| 201 | 20년 전 | 1846 | ||
| 200 | 20년 전 | 2975 | ||
| 199 | 20년 전 | 2019 | ||
| 198 | 20년 전 | 2100 | ||
| 197 | 20년 전 | 3672 | ||
| 196 | 20년 전 | 3013 | ||
| 195 | 20년 전 | 2128 | ||
| 194 | 20년 전 | 10274 | ||
| 193 | 20년 전 | 2271 | ||
| 192 | 20년 전 | 1619 | ||
| 191 | 20년 전 | 2685 | ||
| 190 | 20년 전 | 2305 | ||
| 189 | 20년 전 | 1709 | ||
| 188 | 20년 전 | 1505 | ||
| 187 | 20년 전 | 1929 | ||
| 186 | 20년 전 | 1755 | ||
| 185 | 20년 전 | 1802 | ||
| 184 | 20년 전 | 2386 | ||
| 183 | 20년 전 | 1595 | ||
| 182 | 20년 전 | 1501 | ||
| 181 | 20년 전 | 1642 | ||
| 180 | 20년 전 | 2740 | ||
| 179 | 20년 전 | 1828 | ||
| 178 | 20년 전 | 1879 | ||
| 177 | 20년 전 | 2006 | ||
| 176 | 20년 전 | 1817 | ||
| 175 | 20년 전 | 1887 | ||
| 174 | 20년 전 | 1716 | ||
| 173 | 20년 전 | 2074 | ||
| 172 | 20년 전 | 1799 | ||
| 171 | 20년 전 | 2584 | ||
| 170 | 20년 전 | 2301 | ||
| 169 | 20년 전 | 2580 | ||
| 168 | 20년 전 | 1515 | ||
| 167 | 20년 전 | 1602 | ||
| 166 | 20년 전 | 2175 | ||
| 165 | 20년 전 | 1663 | ||
| 164 | 20년 전 | 3793 | ||
| 163 | 20년 전 | 2691 | ||
| 162 | 20년 전 | 2114 | ||
| 161 | 20년 전 | 2822 | ||
| 160 | 20년 전 | 1759 | ||
| 159 | 20년 전 | 1637 | ||
| 158 | 20년 전 | 2589 | ||
| 157 | 20년 전 | 1516 | ||
| 156 | 20년 전 | 1776 | ||
| 155 | 20년 전 | 3254 | ||
| 154 | 20년 전 | 1925 | ||
| 153 | 20년 전 | 1646 | ||
| 152 | 20년 전 | 4979 | ||
| 151 | 20년 전 | 4602 | ||
| 150 | 20년 전 | 3540 | ||
| 149 | 20년 전 | 3817 | ||
| 148 | 20년 전 | 7102 | ||
| 147 | 20년 전 | 3570 | ||
| 146 | 20년 전 | 2651 | ||
| 145 | 20년 전 | 2642 | ||
| 144 | 20년 전 | 7180 | ||
| 143 | 20년 전 | 4626 | ||
| 142 | 20년 전 | 1914 | ||
| 141 | 20년 전 | 3274 | ||
| 140 | 20년 전 | 1992 | ||
| 139 | 20년 전 | 1616 | ||
| 138 | 20년 전 | 2333 | ||
| 137 | 20년 전 | 1810 | ||
| 136 | 20년 전 | 1476 | ||
| 135 | 20년 전 | 1816 | ||
| 134 | 20년 전 | 2993 | ||
| 133 | 20년 전 | 2474 | ||
| 132 | 20년 전 | 1722 | ||
| 131 | 20년 전 | 1669 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기