데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 485 | ||
| 7929 | 9년 전 | 420 | ||
| 7928 | 9년 전 | 493 | ||
| 7927 | 9년 전 | 403 | ||
| 7926 | 9년 전 | 713 | ||
| 7925 | 9년 전 | 437 | ||
| 7924 | 9년 전 | 418 | ||
| 7923 | 9년 전 | 409 | ||
| 7922 | 9년 전 | 433 | ||
| 7921 | 9년 전 | 448 | ||
| 7920 | 9년 전 | 357 | ||
| 7919 | 9년 전 | 366 | ||
| 7918 | 9년 전 | 515 | ||
| 7917 | 9년 전 | 375 | ||
| 7916 | 9년 전 | 460 | ||
| 7915 | 9년 전 | 479 | ||
| 7914 | 9년 전 | 487 | ||
| 7913 | 9년 전 | 658 | ||
| 7912 | 9년 전 | 496 | ||
| 7911 | 9년 전 | 418 | ||
| 7910 | 9년 전 | 466 | ||
| 7909 | 9년 전 | 582 | ||
| 7908 | 9년 전 | 514 | ||
| 7907 | 9년 전 | 457 | ||
| 7906 | 9년 전 | 478 | ||
| 7905 | 9년 전 | 440 | ||
| 7904 | 9년 전 | 428 | ||
| 7903 | 9년 전 | 438 | ||
| 7902 | 9년 전 | 616 | ||
| 7901 |
|
10년 전 | 787 | |
| 7900 | 10년 전 | 672 | ||
| 7899 | 10년 전 | 460 | ||
| 7898 | 10년 전 | 455 | ||
| 7897 | 10년 전 | 414 | ||
| 7896 | 10년 전 | 430 | ||
| 7895 | 10년 전 | 549 | ||
| 7894 | 10년 전 | 455 | ||
| 7893 | 10년 전 | 429 | ||
| 7892 | 10년 전 | 470 | ||
| 7891 | 10년 전 | 827 | ||
| 7890 | 10년 전 | 1255 | ||
| 7889 | 10년 전 | 798 | ||
| 7888 |
limsy1987
|
10년 전 | 609 | |
| 7887 | 10년 전 | 650 | ||
| 7886 | 10년 전 | 532 | ||
| 7885 | 10년 전 | 501 | ||
| 7884 | 10년 전 | 496 | ||
| 7883 | 10년 전 | 501 | ||
| 7882 | 10년 전 | 557 | ||
| 7881 | 10년 전 | 536 | ||
| 7880 | 10년 전 | 653 | ||
| 7879 | 10년 전 | 544 | ||
| 7878 | 10년 전 | 1306 | ||
| 7877 | 10년 전 | 836 | ||
| 7876 | 10년 전 | 573 | ||
| 7875 | 10년 전 | 645 | ||
| 7874 |
|
10년 전 | 851 | |
| 7873 | 10년 전 | 579 | ||
| 7872 | 10년 전 | 735 | ||
| 7871 | 10년 전 | 553 | ||
| 7870 | 10년 전 | 671 | ||
| 7869 | 10년 전 | 488 | ||
| 7868 | 10년 전 | 529 | ||
| 7867 | 10년 전 | 534 | ||
| 7866 | 10년 전 | 591 | ||
| 7865 | 10년 전 | 534 | ||
| 7864 | 10년 전 | 589 | ||
| 7863 | 10년 전 | 586 | ||
| 7862 | 10년 전 | 558 | ||
| 7861 | 10년 전 | 727 | ||
| 7860 | 10년 전 | 706 | ||
| 7859 | 10년 전 | 473 | ||
| 7858 | 10년 전 | 779 | ||
| 7857 | 10년 전 | 1168 | ||
| 7856 | 10년 전 | 594 | ||
| 7855 | 10년 전 | 836 | ||
| 7854 | 10년 전 | 777 | ||
| 7853 | 10년 전 | 675 | ||
| 7852 | 10년 전 | 591 | ||
| 7851 | 10년 전 | 592 | ||
| 7850 | 10년 전 | 670 | ||
| 7849 | 10년 전 | 444 | ||
| 7848 | 10년 전 | 507 | ||
| 7847 | 10년 전 | 741 | ||
| 7846 | 10년 전 | 526 | ||
| 7845 | 10년 전 | 499 | ||
| 7844 | 10년 전 | 468 | ||
| 7843 | 10년 전 | 506 | ||
| 7842 | 10년 전 | 485 | ||
| 7841 | 10년 전 | 455 | ||
| 7840 | 10년 전 | 480 | ||
| 7839 | 10년 전 | 519 | ||
| 7838 | 10년 전 | 590 | ||
| 7837 | 10년 전 | 419 | ||
| 7836 | 10년 전 | 460 | ||
| 7835 | 10년 전 | 547 | ||
| 7834 |
|
10년 전 | 1248 | |
| 7833 | 10년 전 | 507 | ||
| 7832 | 10년 전 | 491 | ||
| 7831 | 10년 전 | 663 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기