데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6830 |
112211dd
|
11년 전 | 787 | |
| 6829 |
진짜다진짜가나타남
|
11년 전 | 1196 | |
| 6828 | 11년 전 | 818 | ||
| 6827 |
봉보로봉봉
|
11년 전 | 903 | |
| 6826 |
jinion
|
11년 전 | 818 | |
| 6825 | 11년 전 | 801 | ||
| 6824 |
yunkiri486
|
11년 전 | 716 | |
| 6823 |
2donggalbi
|
11년 전 | 850 | |
| 6822 | 11년 전 | 848 | ||
| 6821 | 11년 전 | 799 | ||
| 6820 | 11년 전 | 3102 | ||
| 6819 | 11년 전 | 1249 | ||
| 6818 | 11년 전 | 516 | ||
| 6817 |
|
11년 전 | 604 | |
| 6816 | 11년 전 | 2070 | ||
| 6815 | 11년 전 | 1211 | ||
| 6814 | 11년 전 | 859 | ||
| 6813 | 11년 전 | 602 | ||
| 6812 |
|
11년 전 | 982 | |
| 6811 | 11년 전 | 577 | ||
| 6810 | 11년 전 | 1536 | ||
| 6809 |
낚시가좋아
|
11년 전 | 1047 | |
| 6808 | 11년 전 | 439 | ||
| 6807 | 11년 전 | 760 | ||
| 6806 |
Unhappy
|
11년 전 | 1771 | |
| 6805 | 11년 전 | 1602 | ||
| 6804 | 11년 전 | 1118 | ||
| 6803 | 11년 전 | 557 | ||
| 6802 |
asdfg
|
11년 전 | 1135 | |
| 6801 |
아트귀농인
|
11년 전 | 500 | |
| 6800 | 11년 전 | 2551 | ||
| 6799 | 11년 전 | 1352 | ||
| 6798 | 11년 전 | 1466 | ||
| 6797 | 11년 전 | 626 | ||
| 6796 |
purple63
|
11년 전 | 427 | |
| 6795 | 11년 전 | 2633 | ||
| 6794 |
커네드커네드
|
11년 전 | 957 | |
| 6793 | 11년 전 | 402 | ||
| 6792 | 11년 전 | 2497 | ||
| 6791 | 11년 전 | 514 | ||
| 6790 | 11년 전 | 2255 | ||
| 6789 |
리아빌리티
|
11년 전 | 3093 | |
| 6788 | 11년 전 | 1343 | ||
| 6787 | 11년 전 | 672 | ||
| 6786 | 11년 전 | 388 | ||
| 6785 | 11년 전 | 716 | ||
| 6784 |
|
11년 전 | 846 | |
| 6783 | 11년 전 | 578 | ||
| 6782 | 11년 전 | 3652 | ||
| 6781 |
리아빌리티
|
11년 전 | 481 | |
| 6780 | 11년 전 | 522 | ||
| 6779 | 11년 전 | 476 | ||
| 6778 | 11년 전 | 4682 | ||
| 6777 |
바보온달123
|
11년 전 | 610 | |
| 6776 | 11년 전 | 927 | ||
| 6775 | 11년 전 | 724 | ||
| 6774 |
DANet
|
11년 전 | 636 | |
| 6773 | 11년 전 | 1557 | ||
| 6772 | 11년 전 | 1353 | ||
| 6771 | 11년 전 | 613 | ||
| 6770 | 11년 전 | 1156 | ||
| 6769 | 11년 전 | 949 | ||
| 6768 | 11년 전 | 688 | ||
| 6767 | 11년 전 | 578 | ||
| 6766 | 11년 전 | 1259 | ||
| 6765 |
크림나이트
|
11년 전 | 994 | |
| 6764 | 11년 전 | 1537 | ||
| 6763 | 11년 전 | 2593 | ||
| 6762 | 11년 전 | 530 | ||
| 6761 |
|
11년 전 | 779 | |
| 6760 |
|
11년 전 | 709 | |
| 6759 | 11년 전 | 3343 | ||
| 6758 | 11년 전 | 1007 | ||
| 6757 | 11년 전 | 1266 | ||
| 6756 | 11년 전 | 889 | ||
| 6755 |
|
11년 전 | 568 | |
| 6754 |
|
11년 전 | 709 | |
| 6753 |
|
11년 전 | 1374 | |
| 6752 | 11년 전 | 600 | ||
| 6751 |
|
11년 전 | 649 | |
| 6750 |
|
11년 전 | 2014 | |
| 6749 | 11년 전 | 1207 | ||
| 6748 |
|
11년 전 | 1113 | |
| 6747 | 11년 전 | 1159 | ||
| 6746 | 11년 전 | 831 | ||
| 6745 |
|
11년 전 | 907 | |
| 6744 | 11년 전 | 849 | ||
| 6743 | 11년 전 | 1277 | ||
| 6742 | 11년 전 | 535 | ||
| 6741 |
Abilityarch
|
11년 전 | 603 | |
| 6740 | 11년 전 | 641 | ||
| 6739 |
leewin20
|
11년 전 | 1231 | |
| 6738 | 11년 전 | 502 | ||
| 6737 | 11년 전 | 1215 | ||
| 6736 | 11년 전 | 1252 | ||
| 6735 | 11년 전 | 546 | ||
| 6734 | 11년 전 | 1279 | ||
| 6733 |
RipperTNT
|
11년 전 | 1837 | |
| 6732 |
|
11년 전 | 1335 | |
| 6731 |
|
11년 전 | 1385 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기