데모
<?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년 전 | 371 | ||
| 7829 |
|
9년 전 | 550 | |
| 7828 | 9년 전 | 481 | ||
| 7827 | 9년 전 | 369 | ||
| 7826 | 9년 전 | 375 | ||
| 7825 | 9년 전 | 429 | ||
| 7824 | 9년 전 | 415 | ||
| 7823 | 9년 전 | 318 | ||
| 7822 | 9년 전 | 315 | ||
| 7821 | 9년 전 | 261 | ||
| 7820 | 9년 전 | 313 | ||
| 7819 |
|
9년 전 | 715 | |
| 7818 | 10년 전 | 335 | ||
| 7817 | 10년 전 | 449 | ||
| 7816 | 10년 전 | 353 | ||
| 7815 | 10년 전 | 553 | ||
| 7814 | 10년 전 | 377 | ||
| 7813 | 10년 전 | 314 | ||
| 7812 | 10년 전 | 341 | ||
| 7811 | 10년 전 | 360 | ||
| 7810 | 10년 전 | 486 | ||
| 7809 | 10년 전 | 430 | ||
| 7808 | 10년 전 | 286 | ||
| 7807 | 10년 전 | 350 | ||
| 7806 |
프로그래머7
|
10년 전 | 1305 | |
| 7805 | 10년 전 | 1212 | ||
| 7804 |
zahir1312
|
10년 전 | 740 | |
| 7803 |
|
10년 전 | 1341 | |
| 7802 | 10년 전 | 396 | ||
| 7801 | 10년 전 | 824 | ||
| 7800 | 10년 전 | 1038 | ||
| 7799 | 10년 전 | 497 | ||
| 7798 | 10년 전 | 446 | ||
| 7797 | 10년 전 | 444 | ||
| 7796 | 10년 전 | 298 | ||
| 7795 | 10년 전 | 451 | ||
| 7794 | 10년 전 | 475 | ||
| 7793 | 10년 전 | 991 | ||
| 7792 | 10년 전 | 400 | ||
| 7791 | 10년 전 | 483 | ||
| 7790 | 10년 전 | 448 | ||
| 7789 |
fbastore
|
10년 전 | 1389 | |
| 7788 | 10년 전 | 483 | ||
| 7787 | 10년 전 | 346 | ||
| 7786 | 10년 전 | 500 | ||
| 7785 | 10년 전 | 516 | ||
| 7784 | 10년 전 | 584 | ||
| 7783 | 10년 전 | 385 | ||
| 7782 | 10년 전 | 442 | ||
| 7781 | 10년 전 | 842 | ||
| 7780 | 10년 전 | 775 | ||
| 7779 | 10년 전 | 745 | ||
| 7778 | 10년 전 | 315 | ||
| 7777 | 10년 전 | 391 | ||
| 7776 | 10년 전 | 398 | ||
| 7775 | 10년 전 | 335 | ||
| 7774 | 10년 전 | 597 | ||
| 7773 | 10년 전 | 320 | ||
| 7772 | 10년 전 | 660 | ||
| 7771 | 10년 전 | 326 | ||
| 7770 | 10년 전 | 608 | ||
| 7769 | 10년 전 | 324 | ||
| 7768 | 10년 전 | 544 | ||
| 7767 | 10년 전 | 1115 | ||
| 7766 | 10년 전 | 439 | ||
| 7765 | 10년 전 | 467 | ||
| 7764 |
잘살아보자
|
10년 전 | 323 | |
| 7763 |
|
10년 전 | 1394 | |
| 7762 |
Tosea
|
10년 전 | 1016 | |
| 7761 | 10년 전 | 611 | ||
| 7760 |
잘살아보자
|
10년 전 | 591 | |
| 7759 |
잘살아보자
|
10년 전 | 405 | |
| 7758 |
잘살아보자
|
10년 전 | 525 | |
| 7757 | 10년 전 | 1175 | ||
| 7756 |
ITBANK
|
10년 전 | 1216 | |
| 7755 | 10년 전 | 1893 | ||
| 7754 | 10년 전 | 990 | ||
| 7753 | 10년 전 | 840 | ||
| 7752 | 10년 전 | 1341 | ||
| 7751 |
잘살아보자
|
10년 전 | 468 | |
| 7750 |
잘살아보자
|
10년 전 | 433 | |
| 7749 |
잘살아보자
|
10년 전 | 431 | |
| 7748 |
잘살아보자
|
10년 전 | 418 | |
| 7747 |
잘살아보자
|
10년 전 | 504 | |
| 7746 |
잘살아보자
|
10년 전 | 622 | |
| 7745 |
잘살아보자
|
10년 전 | 866 | |
| 7744 |
잘살아보자
|
10년 전 | 384 | |
| 7743 | 10년 전 | 911 | ||
| 7742 |
starbros
|
10년 전 | 784 | |
| 7741 |
잘살아보자
|
10년 전 | 594 | |
| 7740 |
잘살아보자
|
10년 전 | 473 | |
| 7739 |
잘살아보자
|
10년 전 | 430 | |
| 7738 |
잘살아보자
|
10년 전 | 484 | |
| 7737 |
잘살아보자
|
10년 전 | 438 | |
| 7736 |
잘살아보자
|
10년 전 | 464 | |
| 7735 |
잘살아보자
|
10년 전 | 800 | |
| 7734 |
잘살아보자
|
10년 전 | 388 | |
| 7733 |
잘살아보자
|
10년 전 | 490 | |
| 7732 |
잘살아보자
|
10년 전 | 641 | |
| 7731 |
잘살아보자
|
10년 전 | 568 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기