데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6930 |
SOFTA
|
11년 전 | 5975 | |
| 6929 |
|
11년 전 | 1589 | |
| 6928 | 11년 전 | 1750 | ||
| 6927 | 11년 전 | 1773 | ||
| 6926 | 11년 전 | 1871 | ||
| 6925 | 11년 전 | 2268 | ||
| 6924 | 11년 전 | 3866 | ||
| 6923 | 11년 전 | 2260 | ||
| 6922 |
level999
|
11년 전 | 1033 | |
| 6921 | 11년 전 | 813 | ||
| 6920 | 11년 전 | 944 | ||
| 6919 | 11년 전 | 1055 | ||
| 6918 | 11년 전 | 1310 | ||
| 6917 | 11년 전 | 15425 | ||
| 6916 | 11년 전 | 1425 | ||
| 6915 | 11년 전 | 571 | ||
| 6914 | 11년 전 | 602 | ||
| 6913 | 11년 전 | 874 | ||
| 6912 | 11년 전 | 3125 | ||
| 6911 |
사랑해요79
|
11년 전 | 962 | |
| 6910 | 11년 전 | 740 | ||
| 6909 | 11년 전 | 777 | ||
| 6908 | 11년 전 | 635 | ||
| 6907 | 11년 전 | 827 | ||
| 6906 | 11년 전 | 1583 | ||
| 6905 | 11년 전 | 561 | ||
| 6904 | 11년 전 | 996 | ||
| 6903 | 11년 전 | 1670 | ||
| 6902 |
2donggalbi
|
11년 전 | 511 | |
| 6901 | 11년 전 | 1380 | ||
| 6900 | 11년 전 | 709 | ||
| 6899 | 11년 전 | 854 | ||
| 6898 |
열라뽕똬이
|
11년 전 | 1303 | |
| 6897 |
this1mg
|
11년 전 | 1601 | |
| 6896 |
sbdossb
|
11년 전 | 572 | |
| 6895 |
봉보로봉봉
|
11년 전 | 1145 | |
| 6894 |
똘똘이스머츠
|
11년 전 | 489 | |
| 6893 |
네이비컬러
|
11년 전 | 3638 | |
| 6892 | 11년 전 | 1071 | ||
| 6891 |
네이비컬러
|
11년 전 | 1315 | |
| 6890 | 11년 전 | 1138 | ||
| 6889 | 11년 전 | 581 | ||
| 6888 | 11년 전 | 717 | ||
| 6887 | 11년 전 | 606 | ||
| 6886 | 11년 전 | 5052 | ||
| 6885 | 11년 전 | 550 | ||
| 6884 |
asfasdfd235
|
11년 전 | 569 | |
| 6883 | 11년 전 | 3030 | ||
| 6882 | 11년 전 | 899 | ||
| 6881 | 11년 전 | 4417 | ||
| 6880 | 11년 전 | 1805 | ||
| 6879 |
퍼블리셔지노군
|
11년 전 | 2614 | |
| 6878 | 11년 전 | 549 | ||
| 6877 | 11년 전 | 569 | ||
| 6876 | 11년 전 | 1442 | ||
| 6875 | 11년 전 | 628 | ||
| 6874 | 11년 전 | 1598 | ||
| 6873 | 11년 전 | 1586 | ||
| 6872 | 11년 전 | 4452 | ||
| 6871 |
Abilityarch
|
11년 전 | 960 | |
| 6870 | 11년 전 | 2121 | ||
| 6869 | 11년 전 | 1403 | ||
| 6868 | 11년 전 | 1441 | ||
| 6867 | 11년 전 | 1516 | ||
| 6866 | 11년 전 | 741 | ||
| 6865 | 11년 전 | 1614 | ||
| 6864 | 11년 전 | 465 | ||
| 6863 | 11년 전 | 3745 | ||
| 6862 | 11년 전 | 1845 | ||
| 6861 | 11년 전 | 1642 | ||
| 6860 | 11년 전 | 1287 | ||
| 6859 |
cityman
|
11년 전 | 6806 | |
| 6858 | 11년 전 | 1259 | ||
| 6857 |
의정부아줌마
|
11년 전 | 858 | |
| 6856 | 11년 전 | 2363 | ||
| 6855 | 11년 전 | 1694 | ||
| 6854 | 11년 전 | 822 | ||
| 6853 | 11년 전 | 1206 | ||
| 6852 | 11년 전 | 2590 | ||
| 6851 | 11년 전 | 1958 | ||
| 6850 | 11년 전 | 1785 | ||
| 6849 | 11년 전 | 2073 | ||
| 6848 | 11년 전 | 2353 | ||
| 6847 | 11년 전 | 3129 | ||
| 6846 | 11년 전 | 2713 | ||
| 6845 | 11년 전 | 2799 | ||
| 6844 | 11년 전 | 3515 | ||
| 6843 | 11년 전 | 3260 | ||
| 6842 |
아트291
|
11년 전 | 688 | |
| 6841 | 11년 전 | 4167 | ||
| 6840 | 11년 전 | 5181 | ||
| 6839 | 11년 전 | 886 | ||
| 6838 |
|
11년 전 | 2094 | |
| 6837 | 11년 전 | 1277 | ||
| 6836 |
netdf
|
11년 전 | 607 | |
| 6835 |
|
11년 전 | 1001 | |
| 6834 | 11년 전 | 667 | ||
| 6833 |
|
11년 전 | 2675 | |
| 6832 |
울산굿모닝
|
11년 전 | 1650 | |
| 6831 |
|
11년 전 | 664 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기