데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7730 | 10년 전 | 1309 | ||
| 7729 | 10년 전 | 1144 | ||
| 7728 |
잘살아보자
|
10년 전 | 598 | |
| 7727 |
잘살아보자
|
10년 전 | 496 | |
| 7726 |
잘살아보자
|
10년 전 | 822 | |
| 7725 |
잘살아보자
|
10년 전 | 552 | |
| 7724 |
잘살아보자
|
10년 전 | 463 | |
| 7723 |
잘살아보자
|
10년 전 | 529 | |
| 7722 |
잘살아보자
|
10년 전 | 476 | |
| 7721 |
잘살아보자
|
10년 전 | 507 | |
| 7720 |
잘살아보자
|
10년 전 | 463 | |
| 7719 |
비긴어게인
|
10년 전 | 690 | |
| 7718 |
|
10년 전 | 2536 | |
| 7717 |
잘살아보자
|
10년 전 | 649 | |
| 7716 |
잘살아보자
|
10년 전 | 396 | |
| 7715 |
잘살아보자
|
10년 전 | 429 | |
| 7714 |
잘살아보자
|
10년 전 | 495 | |
| 7713 | 10년 전 | 1785 | ||
| 7712 | 10년 전 | 1713 | ||
| 7711 | 10년 전 | 1100 | ||
| 7710 | 10년 전 | 1400 | ||
| 7709 | 10년 전 | 1517 | ||
| 7708 | 10년 전 | 1459 | ||
| 7707 | 10년 전 | 857 | ||
| 7706 |
별지기천사
|
10년 전 | 569 | |
| 7705 | 10년 전 | 1072 | ||
| 7704 |
ICONdesignstudio
|
10년 전 | 618 | |
| 7703 | 10년 전 | 590 | ||
| 7702 |
|
10년 전 | 724 | |
| 7701 | 10년 전 | 1410 | ||
| 7700 | 10년 전 | 1106 | ||
| 7699 | 10년 전 | 582 | ||
| 7698 | 10년 전 | 1140 | ||
| 7697 | 10년 전 | 5164 | ||
| 7696 | 10년 전 | 653 | ||
| 7695 | 10년 전 | 1687 | ||
| 7694 | 10년 전 | 1057 | ||
| 7693 | 10년 전 | 1554 | ||
| 7692 | 10년 전 | 1295 | ||
| 7691 | 10년 전 | 816 | ||
| 7690 | 10년 전 | 1389 | ||
| 7689 | 10년 전 | 1016 | ||
| 7688 | 10년 전 | 613 | ||
| 7687 |
파랑새1597
|
10년 전 | 591 | |
| 7686 | 10년 전 | 850 | ||
| 7685 | 10년 전 | 1340 | ||
| 7684 | 10년 전 | 799 | ||
| 7683 | 10년 전 | 1096 | ||
| 7682 | 10년 전 | 1014 | ||
| 7681 | 10년 전 | 656 | ||
| 7680 | 10년 전 | 989 | ||
| 7679 | 10년 전 | 505 | ||
| 7678 | 10년 전 | 736 | ||
| 7677 | 10년 전 | 635 | ||
| 7676 |
|
10년 전 | 945 | |
| 7675 |
|
10년 전 | 1176 | |
| 7674 | 10년 전 | 1050 | ||
| 7673 | 10년 전 | 753 | ||
| 7672 | 10년 전 | 1091 | ||
| 7671 | 10년 전 | 889 | ||
| 7670 | 10년 전 | 655 | ||
| 7669 |
mashmellow
|
10년 전 | 1232 | |
| 7668 | 10년 전 | 718 | ||
| 7667 | 10년 전 | 1009 | ||
| 7666 |
senseme
|
10년 전 | 654 | |
| 7665 | 10년 전 | 506 | ||
| 7664 | 10년 전 | 1895 | ||
| 7663 |
mixx애교
|
10년 전 | 983 | |
| 7662 | 10년 전 | 1039 | ||
| 7661 |
hkhkah
|
10년 전 | 788 | |
| 7660 | 10년 전 | 1062 | ||
| 7659 |
커네드커네드
|
10년 전 | 930 | |
| 7658 |
바람돌이팡
|
10년 전 | 672 | |
| 7657 | 10년 전 | 1165 | ||
| 7656 | 10년 전 | 1570 | ||
| 7655 | 10년 전 | 986 | ||
| 7654 |
개발짜증나
|
10년 전 | 856 | |
| 7653 |
네이비칼라
|
10년 전 | 879 | |
| 7652 |
밥먹고합시다
|
10년 전 | 815 | |
| 7651 |
플라이SINJI
|
10년 전 | 1512 | |
| 7650 |
개발짜증나
|
10년 전 | 1417 | |
| 7649 | 10년 전 | 454 | ||
| 7648 |
이미영ㅇㅇ
|
10년 전 | 864 | |
| 7647 | 10년 전 | 437 | ||
| 7646 | 10년 전 | 805 | ||
| 7645 | 10년 전 | 2320 | ||
| 7644 | 10년 전 | 819 | ||
| 7643 |
|
10년 전 | 2872 | |
| 7642 | 10년 전 | 1509 | ||
| 7641 | 10년 전 | 1140 | ||
| 7640 |
개발짜증나
|
10년 전 | 475 | |
| 7639 |
|
10년 전 | 812 | |
| 7638 |
개발짜증나
|
10년 전 | 1133 | |
| 7637 | 10년 전 | 1549 | ||
| 7636 | 10년 전 | 2916 | ||
| 7635 | 10년 전 | 1695 | ||
| 7634 | 10년 전 | 1884 | ||
| 7633 | 10년 전 | 2337 | ||
| 7632 | 10년 전 | 3945 | ||
| 7631 |
|
10년 전 | 1533 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기