데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7830 | 9년 전 | 393 | ||
| 7829 |
|
9년 전 | 570 | |
| 7828 | 9년 전 | 502 | ||
| 7827 | 9년 전 | 388 | ||
| 7826 | 9년 전 | 404 | ||
| 7825 | 9년 전 | 447 | ||
| 7824 | 9년 전 | 426 | ||
| 7823 | 9년 전 | 340 | ||
| 7822 | 10년 전 | 333 | ||
| 7821 | 10년 전 | 284 | ||
| 7820 | 10년 전 | 330 | ||
| 7819 |
|
10년 전 | 732 | |
| 7818 | 10년 전 | 363 | ||
| 7817 | 10년 전 | 482 | ||
| 7816 | 10년 전 | 382 | ||
| 7815 | 10년 전 | 584 | ||
| 7814 | 10년 전 | 411 | ||
| 7813 | 10년 전 | 350 | ||
| 7812 | 10년 전 | 364 | ||
| 7811 | 10년 전 | 372 | ||
| 7810 | 10년 전 | 528 | ||
| 7809 | 10년 전 | 455 | ||
| 7808 | 10년 전 | 338 | ||
| 7807 | 10년 전 | 379 | ||
| 7806 |
프로그래머7
|
10년 전 | 1313 | |
| 7805 | 10년 전 | 1246 | ||
| 7804 |
zahir1312
|
10년 전 | 755 | |
| 7803 |
|
10년 전 | 1352 | |
| 7802 | 10년 전 | 438 | ||
| 7801 | 10년 전 | 841 | ||
| 7800 | 10년 전 | 1071 | ||
| 7799 | 10년 전 | 521 | ||
| 7798 | 10년 전 | 478 | ||
| 7797 | 10년 전 | 480 | ||
| 7796 | 10년 전 | 317 | ||
| 7795 | 10년 전 | 474 | ||
| 7794 | 10년 전 | 510 | ||
| 7793 | 10년 전 | 1021 | ||
| 7792 | 10년 전 | 426 | ||
| 7791 | 10년 전 | 518 | ||
| 7790 | 10년 전 | 476 | ||
| 7789 |
fbastore
|
10년 전 | 1415 | |
| 7788 | 10년 전 | 510 | ||
| 7787 | 10년 전 | 372 | ||
| 7786 | 10년 전 | 535 | ||
| 7785 | 10년 전 | 545 | ||
| 7784 | 10년 전 | 609 | ||
| 7783 | 10년 전 | 419 | ||
| 7782 | 10년 전 | 461 | ||
| 7781 | 10년 전 | 876 | ||
| 7780 | 10년 전 | 794 | ||
| 7779 | 10년 전 | 761 | ||
| 7778 | 10년 전 | 335 | ||
| 7777 | 10년 전 | 423 | ||
| 7776 | 10년 전 | 429 | ||
| 7775 | 10년 전 | 372 | ||
| 7774 | 10년 전 | 613 | ||
| 7773 | 10년 전 | 357 | ||
| 7772 | 10년 전 | 694 | ||
| 7771 | 10년 전 | 347 | ||
| 7770 | 10년 전 | 627 | ||
| 7769 | 10년 전 | 349 | ||
| 7768 | 10년 전 | 574 | ||
| 7767 | 10년 전 | 1138 | ||
| 7766 | 10년 전 | 463 | ||
| 7765 | 10년 전 | 491 | ||
| 7764 |
잘살아보자
|
10년 전 | 349 | |
| 7763 |
|
10년 전 | 1421 | |
| 7762 |
Tosea
|
10년 전 | 1031 | |
| 7761 | 10년 전 | 619 | ||
| 7760 |
잘살아보자
|
10년 전 | 643 | |
| 7759 |
잘살아보자
|
10년 전 | 469 | |
| 7758 |
잘살아보자
|
10년 전 | 559 | |
| 7757 | 10년 전 | 1210 | ||
| 7756 |
ITBANK
|
10년 전 | 1235 | |
| 7755 | 10년 전 | 1913 | ||
| 7754 | 10년 전 | 1028 | ||
| 7753 | 10년 전 | 854 | ||
| 7752 | 10년 전 | 1365 | ||
| 7751 |
잘살아보자
|
10년 전 | 496 | |
| 7750 |
잘살아보자
|
10년 전 | 452 | |
| 7749 |
잘살아보자
|
10년 전 | 457 | |
| 7748 |
잘살아보자
|
10년 전 | 446 | |
| 7747 |
잘살아보자
|
10년 전 | 547 | |
| 7746 |
잘살아보자
|
10년 전 | 657 | |
| 7745 |
잘살아보자
|
10년 전 | 894 | |
| 7744 |
잘살아보자
|
10년 전 | 402 | |
| 7743 | 10년 전 | 926 | ||
| 7742 |
starbros
|
10년 전 | 811 | |
| 7741 |
잘살아보자
|
10년 전 | 636 | |
| 7740 |
잘살아보자
|
10년 전 | 501 | |
| 7739 |
잘살아보자
|
10년 전 | 447 | |
| 7738 |
잘살아보자
|
10년 전 | 507 | |
| 7737 |
잘살아보자
|
10년 전 | 468 | |
| 7736 |
잘살아보자
|
10년 전 | 486 | |
| 7735 |
잘살아보자
|
10년 전 | 821 | |
| 7734 |
잘살아보자
|
10년 전 | 413 | |
| 7733 |
잘살아보자
|
10년 전 | 518 | |
| 7732 |
잘살아보자
|
10년 전 | 674 | |
| 7731 |
잘살아보자
|
10년 전 | 596 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기