데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 635 | ||
| 7629 |
|
10년 전 | 2347 | |
| 7628 | 10년 전 | 769 | ||
| 7627 |
|
10년 전 | 1002 | |
| 7626 |
|
10년 전 | 1761 | |
| 7625 | 10년 전 | 661 | ||
| 7624 | 10년 전 | 684 | ||
| 7623 |
|
10년 전 | 3011 | |
| 7622 | 10년 전 | 698 | ||
| 7621 |
leeleeleelee
|
10년 전 | 571 | |
| 7620 | 10년 전 | 529 | ||
| 7619 | 10년 전 | 460 | ||
| 7618 | 10년 전 | 1000 | ||
| 7617 | 10년 전 | 713 | ||
| 7616 | 10년 전 | 615 | ||
| 7615 | 10년 전 | 712 | ||
| 7614 | 10년 전 | 1218 | ||
| 7613 |
|
10년 전 | 2057 | |
| 7612 | 10년 전 | 1125 | ||
| 7611 | 10년 전 | 1385 | ||
| 7610 |
|
10년 전 | 1875 | |
| 7609 |
|
10년 전 | 1295 | |
| 7608 |
mwdkim
|
10년 전 | 1099 | |
| 7607 |
|
10년 전 | 1024 | |
| 7606 |
mwdkim
|
10년 전 | 3904 | |
| 7605 | 10년 전 | 669 | ||
| 7604 | 10년 전 | 1007 | ||
| 7603 | 10년 전 | 1631 | ||
| 7602 |
|
10년 전 | 1041 | |
| 7601 |
AniNest
|
10년 전 | 2763 | |
| 7600 |
port443
|
10년 전 | 1002 | |
| 7599 | 10년 전 | 924 | ||
| 7598 | 10년 전 | 991 | ||
| 7597 | 10년 전 | 4554 | ||
| 7596 |
SeungYeon
|
10년 전 | 868 | |
| 7595 |
untitled
|
10년 전 | 2396 | |
| 7594 |
프로그래머7
|
10년 전 | 1700 | |
| 7593 |
untitled
|
10년 전 | 2338 | |
| 7592 |
untitled
|
10년 전 | 1918 | |
| 7591 |
untitled
|
10년 전 | 2653 | |
| 7590 |
아리마2001
|
10년 전 | 824 | |
| 7589 | 10년 전 | 1084 | ||
| 7588 |
|
10년 전 | 2902 | |
| 7587 | 10년 전 | 1279 | ||
| 7586 | 10년 전 | 644 | ||
| 7585 | 10년 전 | 1664 | ||
| 7584 | 10년 전 | 1396 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1140 | |
| 7582 |
|
10년 전 | 1074 | |
| 7581 | 10년 전 | 1306 | ||
| 7580 | 10년 전 | 947 | ||
| 7579 |
|
10년 전 | 586 | |
| 7578 | 10년 전 | 1398 | ||
| 7577 |
|
10년 전 | 1853 | |
| 7576 | 10년 전 | 1368 | ||
| 7575 |
멋진남자임
|
10년 전 | 1447 | |
| 7574 | 10년 전 | 2089 | ||
| 7573 | 10년 전 | 3221 | ||
| 7572 | 10년 전 | 750 | ||
| 7571 |
|
10년 전 | 772 | |
| 7570 |
|
10년 전 | 1295 | |
| 7569 | 10년 전 | 1524 | ||
| 7568 |
this1mg
|
10년 전 | 1024 | |
| 7567 |
|
10년 전 | 734 | |
| 7566 | 10년 전 | 903 | ||
| 7565 |
Angel하늘
|
10년 전 | 966 | |
| 7564 |
seoldi
|
10년 전 | 1211 | |
| 7563 |
|
10년 전 | 1353 | |
| 7562 |
멋진남자임
|
10년 전 | 2049 | |
| 7561 | 10년 전 | 684 | ||
| 7560 |
leeleeleelee
|
10년 전 | 883 | |
| 7559 | 10년 전 | 5014 | ||
| 7558 |
RinaP
|
10년 전 | 756 | |
| 7557 |
|
10년 전 | 1222 | |
| 7556 | 10년 전 | 1172 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1637 | |
| 7554 | 10년 전 | 1076 | ||
| 7553 |
senseme
|
10년 전 | 1322 | |
| 7552 |
ehdltdoit
|
10년 전 | 1419 | |
| 7551 |
|
10년 전 | 1803 | |
| 7550 |
leeleeleelee
|
10년 전 | 1567 | |
| 7549 | 10년 전 | 2397 | ||
| 7548 | 10년 전 | 1816 | ||
| 7547 |
멋진남자임
|
10년 전 | 1932 | |
| 7546 | 10년 전 | 974 | ||
| 7545 |
ILMare1003
|
10년 전 | 1258 | |
| 7544 |
|
10년 전 | 1211 | |
| 7543 | 10년 전 | 866 | ||
| 7542 | 10년 전 | 637 | ||
| 7541 |
울라라라우
|
10년 전 | 850 | |
| 7540 | 10년 전 | 1586 | ||
| 7539 | 10년 전 | 905 | ||
| 7538 |
|
10년 전 | 1816 | |
| 7537 | 10년 전 | 3593 | ||
| 7536 |
Gaumi
|
10년 전 | 1389 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1248 | |
| 7534 |
senseme
|
10년 전 | 1195 | |
| 7533 | 10년 전 | 1172 | ||
| 7532 | 10년 전 | 837 | ||
| 7531 | 10년 전 | 2029 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기