데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7430 |
|
11년 전 | 4953 | |
| 7429 | 11년 전 | 1785 | ||
| 7428 |
멋진남자임
|
11년 전 | 1176 | |
| 7427 |
sdflksdj2
|
11년 전 | 836 | |
| 7426 | 11년 전 | 1371 | ||
| 7425 | 11년 전 | 1400 | ||
| 7424 | 11년 전 | 1062 | ||
| 7423 |
SeungYeon
|
11년 전 | 572 | |
| 7422 | 11년 전 | 818 | ||
| 7421 |
sdflksdj2
|
11년 전 | 699 | |
| 7420 | 11년 전 | 979 | ||
| 7419 |
|
11년 전 | 1416 | |
| 7418 |
멋진남자임
|
11년 전 | 1448 | |
| 7417 | 11년 전 | 618 | ||
| 7416 |
senseme
|
11년 전 | 1244 | |
| 7415 | 11년 전 | 972 | ||
| 7414 | 11년 전 | 722 | ||
| 7413 | 11년 전 | 4856 | ||
| 7412 | 11년 전 | 4412 | ||
| 7411 |
holla
|
11년 전 | 904 | |
| 7410 | 11년 전 | 4262 | ||
| 7409 | 11년 전 | 3934 | ||
| 7408 | 11년 전 | 4277 | ||
| 7407 | 11년 전 | 5102 | ||
| 7406 | 11년 전 | 4742 | ||
| 7405 | 11년 전 | 4312 | ||
| 7404 | 11년 전 | 771 | ||
| 7403 | 11년 전 | 5698 | ||
| 7402 | 11년 전 | 1532 | ||
| 7401 |
|
11년 전 | 986 | |
| 7400 | 11년 전 | 2983 | ||
| 7399 |
멋진남자임
|
11년 전 | 931 | |
| 7398 |
파랑새1597
|
11년 전 | 2722 | |
| 7397 | 11년 전 | 2284 | ||
| 7396 |
basketball
|
11년 전 | 1384 | |
| 7395 | 11년 전 | 1624 | ||
| 7394 | 11년 전 | 943 | ||
| 7393 | 11년 전 | 2085 | ||
| 7392 | 11년 전 | 860 | ||
| 7391 |
잘살아보자
|
11년 전 | 5374 | |
| 7390 |
잘살아보자
|
11년 전 | 2235 | |
| 7389 |
잘살아보자
|
11년 전 | 3326 | |
| 7388 |
파랑새1597
|
11년 전 | 940 | |
| 7387 | 11년 전 | 1110 | ||
| 7386 |
프리랜서퍼블리셔
|
11년 전 | 978 | |
| 7385 | 11년 전 | 1583 | ||
| 7384 |
울라라라우
|
11년 전 | 901 | |
| 7383 | 11년 전 | 1566 | ||
| 7382 |
잘살아보자
|
11년 전 | 4240 | |
| 7381 |
잘살아보자
|
11년 전 | 2013 | |
| 7380 |
잘살아보자
|
11년 전 | 1957 | |
| 7379 |
잘살아보자
|
11년 전 | 5917 | |
| 7378 |
senseme
|
11년 전 | 1915 | |
| 7377 |
잘살아보자
|
11년 전 | 2758 | |
| 7376 | 11년 전 | 2425 | ||
| 7375 |
잘살아보자
|
11년 전 | 1062 | |
| 7374 |
잘살아보자
|
11년 전 | 3172 | |
| 7373 |
잘살아보자
|
11년 전 | 2494 | |
| 7372 |
잘살아보자
|
11년 전 | 5840 | |
| 7371 |
잘살아보자
|
11년 전 | 3474 | |
| 7370 |
잘살아보자
|
11년 전 | 1923 | |
| 7369 |
잘살아보자
|
11년 전 | 2180 | |
| 7368 |
ksdhtm56
|
11년 전 | 577 | |
| 7367 | 11년 전 | 1450 | ||
| 7366 | 11년 전 | 941 | ||
| 7365 | 11년 전 | 3561 | ||
| 7364 |
잘살아보자
|
11년 전 | 1406 | |
| 7363 |
잘살아보자
|
11년 전 | 1390 | |
| 7362 |
잘살아보자
|
11년 전 | 1525 | |
| 7361 | 11년 전 | 3614 | ||
| 7360 | 11년 전 | 3575 | ||
| 7359 | 11년 전 | 3394 | ||
| 7358 |
멋진남자임
|
11년 전 | 1049 | |
| 7357 | 11년 전 | 3425 | ||
| 7356 | 11년 전 | 2611 | ||
| 7355 | 11년 전 | 3208 | ||
| 7354 |
파랑새1597
|
11년 전 | 660 | |
| 7353 |
잘살아보자
|
11년 전 | 2434 | |
| 7352 |
잘살아보자
|
11년 전 | 2430 | |
| 7351 |
잘살아보자
|
11년 전 | 2485 | |
| 7350 |
잘살아보자
|
11년 전 | 1490 | |
| 7349 |
잘살아보자
|
11년 전 | 1976 | |
| 7348 |
잘살아보자
|
11년 전 | 1298 | |
| 7347 |
잘살아보자
|
11년 전 | 1092 | |
| 7346 |
멋진남자임
|
11년 전 | 1660 | |
| 7345 | 11년 전 | 1013 | ||
| 7344 | 11년 전 | 3887 | ||
| 7343 | 11년 전 | 3674 | ||
| 7342 | 11년 전 | 1296 | ||
| 7341 | 11년 전 | 2539 | ||
| 7340 |
|
11년 전 | 950 | |
| 7339 | 11년 전 | 1745 | ||
| 7338 | 11년 전 | 3362 | ||
| 7337 | 11년 전 | 3675 | ||
| 7336 | 11년 전 | 4613 | ||
| 7335 | 11년 전 | 989 | ||
| 7334 | 11년 전 | 1547 | ||
| 7333 | 11년 전 | 2952 | ||
| 7332 |
|
11년 전 | 1124 | |
| 7331 |
KeePin뽁이
|
11년 전 | 1112 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기