데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7530 | 10년 전 | 780 | ||
| 7529 |
파랑새1597
|
10년 전 | 1198 | |
| 7528 |
파랑새1597
|
10년 전 | 1303 | |
| 7527 |
integrity7
|
10년 전 | 1380 | |
| 7526 | 10년 전 | 2402 | ||
| 7525 |
다빈치코드777
|
10년 전 | 1094 | |
| 7524 | 10년 전 | 1558 | ||
| 7523 | 10년 전 | 953 | ||
| 7522 |
|
10년 전 | 985 | |
| 7521 |
blackkil
|
10년 전 | 1859 | |
| 7520 | 10년 전 | 1279 | ||
| 7519 |
Gaumi
|
10년 전 | 1073 | |
| 7518 | 10년 전 | 1474 | ||
| 7517 | 10년 전 | 816 | ||
| 7516 | 10년 전 | 1279 | ||
| 7515 | 10년 전 | 1392 | ||
| 7514 |
|
10년 전 | 4483 | |
| 7513 |
멋진남자임
|
10년 전 | 1133 | |
| 7512 |
다빈치코드777
|
10년 전 | 864 | |
| 7511 |
|
10년 전 | 3385 | |
| 7510 | 10년 전 | 1359 | ||
| 7509 | 10년 전 | 1134 | ||
| 7508 | 10년 전 | 711 | ||
| 7507 |
senseme
|
10년 전 | 734 | |
| 7506 |
멋진남자임
|
10년 전 | 1626 | |
| 7505 | 10년 전 | 3987 | ||
| 7504 | 10년 전 | 2139 | ||
| 7503 | 10년 전 | 988 | ||
| 7502 | 10년 전 | 514 | ||
| 7501 | 10년 전 | 1435 | ||
| 7500 | 10년 전 | 1483 | ||
| 7499 | 10년 전 | 3372 | ||
| 7498 | 10년 전 | 1195 | ||
| 7497 |
dethos79
|
10년 전 | 2956 | |
| 7496 | 10년 전 | 2138 | ||
| 7495 | 10년 전 | 849 | ||
| 7494 |
CHAVO
|
10년 전 | 1121 | |
| 7493 | 10년 전 | 2642 | ||
| 7492 | 10년 전 | 1253 | ||
| 7491 | 10년 전 | 1459 | ||
| 7490 | 10년 전 | 2325 | ||
| 7489 | 10년 전 | 2117 | ||
| 7488 |
toptopon
|
10년 전 | 887 | |
| 7487 |
|
10년 전 | 1025 | |
| 7486 | 10년 전 | 3343 | ||
| 7485 | 10년 전 | 1306 | ||
| 7484 | 10년 전 | 1364 | ||
| 7483 | 10년 전 | 1018 | ||
| 7482 | 10년 전 | 646 | ||
| 7481 | 10년 전 | 854 | ||
| 7480 | 10년 전 | 1218 | ||
| 7479 | 10년 전 | 2596 | ||
| 7478 | 10년 전 | 1154 | ||
| 7477 |
멋진남자임
|
10년 전 | 1505 | |
| 7476 |
zeppeto
|
10년 전 | 1138 | |
| 7475 |
200점아빠
|
10년 전 | 908 | |
| 7474 | 10년 전 | 4000 | ||
| 7473 | 10년 전 | 984 | ||
| 7472 |
나르시스1
|
10년 전 | 1233 | |
| 7471 | 10년 전 | 869 | ||
| 7470 | 10년 전 | 1268 | ||
| 7469 |
플라이SINJI
|
10년 전 | 959 | |
| 7468 |
|
10년 전 | 538 | |
| 7467 |
|
10년 전 | 646 | |
| 7466 | 10년 전 | 1108 | ||
| 7465 | 10년 전 | 1176 | ||
| 7464 |
|
10년 전 | 1180 | |
| 7463 | 10년 전 | 1235 | ||
| 7462 |
진짜별사탕
|
10년 전 | 849 | |
| 7461 | 10년 전 | 936 | ||
| 7460 | 10년 전 | 3718 | ||
| 7459 |
멋진남자임
|
10년 전 | 1546 | |
| 7458 |
멋진남자임
|
10년 전 | 477 | |
| 7457 | 10년 전 | 912 | ||
| 7456 | 10년 전 | 754 | ||
| 7455 | 10년 전 | 2142 | ||
| 7454 | 10년 전 | 627 | ||
| 7453 | 10년 전 | 818 | ||
| 7452 |
중국어사이트제작
|
10년 전 | 502 | |
| 7451 | 10년 전 | 900 | ||
| 7450 | 10년 전 | 624 | ||
| 7449 |
울라라라우
|
10년 전 | 943 | |
| 7448 | 10년 전 | 1626 | ||
| 7447 |
멋진남자임
|
10년 전 | 493 | |
| 7446 | 10년 전 | 542 | ||
| 7445 |
네이비칼라
|
10년 전 | 1665 | |
| 7444 |
senseme
|
10년 전 | 1397 | |
| 7443 | 10년 전 | 1332 | ||
| 7442 | 10년 전 | 722 | ||
| 7441 |
멋진남자임
|
10년 전 | 1427 | |
| 7440 | 10년 전 | 888 | ||
| 7439 |
|
10년 전 | 745 | |
| 7438 |
|
10년 전 | 924 | |
| 7437 |
basement
|
10년 전 | 1026 | |
| 7436 |
잘살아보자
|
10년 전 | 1118 | |
| 7435 | 10년 전 | 1076 | ||
| 7434 | 10년 전 | 3788 | ||
| 7433 |
|
10년 전 | 2728 | |
| 7432 |
alexkim
|
10년 전 | 856 | |
| 7431 |
이웃집초보
|
11년 전 | 1300 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기