데모
<?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년 전 | 1319 | ||
| 7729 | 10년 전 | 1174 | ||
| 7728 |
잘살아보자
|
10년 전 | 618 | |
| 7727 |
잘살아보자
|
10년 전 | 519 | |
| 7726 |
잘살아보자
|
10년 전 | 846 | |
| 7725 |
잘살아보자
|
10년 전 | 571 | |
| 7724 |
잘살아보자
|
10년 전 | 492 | |
| 7723 |
잘살아보자
|
10년 전 | 554 | |
| 7722 |
잘살아보자
|
10년 전 | 493 | |
| 7721 |
잘살아보자
|
10년 전 | 522 | |
| 7720 |
잘살아보자
|
10년 전 | 489 | |
| 7719 |
비긴어게인
|
10년 전 | 702 | |
| 7718 |
|
10년 전 | 2549 | |
| 7717 |
잘살아보자
|
10년 전 | 672 | |
| 7716 |
잘살아보자
|
10년 전 | 419 | |
| 7715 |
잘살아보자
|
10년 전 | 450 | |
| 7714 |
잘살아보자
|
10년 전 | 512 | |
| 7713 | 10년 전 | 1795 | ||
| 7712 | 10년 전 | 1731 | ||
| 7711 | 10년 전 | 1119 | ||
| 7710 | 10년 전 | 1413 | ||
| 7709 | 10년 전 | 1534 | ||
| 7708 | 10년 전 | 1474 | ||
| 7707 | 10년 전 | 867 | ||
| 7706 |
별지기천사
|
10년 전 | 582 | |
| 7705 | 10년 전 | 1087 | ||
| 7704 |
ICONdesignstudio
|
10년 전 | 643 | |
| 7703 | 10년 전 | 609 | ||
| 7702 |
|
10년 전 | 746 | |
| 7701 | 10년 전 | 1436 | ||
| 7700 | 10년 전 | 1116 | ||
| 7699 | 10년 전 | 589 | ||
| 7698 | 10년 전 | 1162 | ||
| 7697 | 10년 전 | 5185 | ||
| 7696 | 10년 전 | 674 | ||
| 7695 | 10년 전 | 1700 | ||
| 7694 | 10년 전 | 1085 | ||
| 7693 | 10년 전 | 1573 | ||
| 7692 | 10년 전 | 1316 | ||
| 7691 | 10년 전 | 840 | ||
| 7690 | 10년 전 | 1403 | ||
| 7689 | 10년 전 | 1031 | ||
| 7688 | 10년 전 | 636 | ||
| 7687 |
파랑새1597
|
10년 전 | 616 | |
| 7686 | 10년 전 | 869 | ||
| 7685 | 10년 전 | 1354 | ||
| 7684 | 10년 전 | 811 | ||
| 7683 | 10년 전 | 1125 | ||
| 7682 | 10년 전 | 1039 | ||
| 7681 | 10년 전 | 686 | ||
| 7680 | 10년 전 | 1003 | ||
| 7679 | 10년 전 | 523 | ||
| 7678 | 10년 전 | 753 | ||
| 7677 | 10년 전 | 655 | ||
| 7676 |
|
10년 전 | 960 | |
| 7675 |
|
10년 전 | 1199 | |
| 7674 | 10년 전 | 1063 | ||
| 7673 | 10년 전 | 770 | ||
| 7672 | 10년 전 | 1110 | ||
| 7671 | 10년 전 | 922 | ||
| 7670 | 10년 전 | 686 | ||
| 7669 |
mashmellow
|
10년 전 | 1242 | |
| 7668 | 10년 전 | 731 | ||
| 7667 | 10년 전 | 1032 | ||
| 7666 |
senseme
|
10년 전 | 672 | |
| 7665 | 10년 전 | 527 | ||
| 7664 | 10년 전 | 1910 | ||
| 7663 |
mixx애교
|
10년 전 | 993 | |
| 7662 | 10년 전 | 1059 | ||
| 7661 |
hkhkah
|
10년 전 | 803 | |
| 7660 | 10년 전 | 1076 | ||
| 7659 |
커네드커네드
|
10년 전 | 949 | |
| 7658 |
바람돌이팡
|
10년 전 | 690 | |
| 7657 | 10년 전 | 1180 | ||
| 7656 | 10년 전 | 1592 | ||
| 7655 | 10년 전 | 1012 | ||
| 7654 |
개발짜증나
|
10년 전 | 871 | |
| 7653 |
네이비칼라
|
10년 전 | 896 | |
| 7652 |
밥먹고합시다
|
10년 전 | 821 | |
| 7651 |
플라이SINJI
|
10년 전 | 1524 | |
| 7650 |
개발짜증나
|
10년 전 | 1430 | |
| 7649 | 10년 전 | 469 | ||
| 7648 |
이미영ㅇㅇ
|
10년 전 | 887 | |
| 7647 | 10년 전 | 461 | ||
| 7646 | 10년 전 | 830 | ||
| 7645 | 10년 전 | 2338 | ||
| 7644 | 10년 전 | 836 | ||
| 7643 |
|
10년 전 | 2889 | |
| 7642 | 10년 전 | 1532 | ||
| 7641 | 10년 전 | 1151 | ||
| 7640 |
개발짜증나
|
10년 전 | 480 | |
| 7639 |
|
10년 전 | 824 | |
| 7638 |
개발짜증나
|
10년 전 | 1148 | |
| 7637 | 10년 전 | 1568 | ||
| 7636 | 10년 전 | 2923 | ||
| 7635 | 10년 전 | 1716 | ||
| 7634 | 10년 전 | 1899 | ||
| 7633 | 10년 전 | 2365 | ||
| 7632 | 10년 전 | 3971 | ||
| 7631 |
|
10년 전 | 1562 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기