데모
<?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년 전 | 1277 | ||
| 7729 | 10년 전 | 1087 | ||
| 7728 |
잘살아보자
|
10년 전 | 556 | |
| 7727 |
잘살아보자
|
10년 전 | 458 | |
| 7726 |
잘살아보자
|
10년 전 | 794 | |
| 7725 |
잘살아보자
|
10년 전 | 520 | |
| 7724 |
잘살아보자
|
10년 전 | 429 | |
| 7723 |
잘살아보자
|
10년 전 | 497 | |
| 7722 |
잘살아보자
|
10년 전 | 435 | |
| 7721 |
잘살아보자
|
10년 전 | 472 | |
| 7720 |
잘살아보자
|
10년 전 | 411 | |
| 7719 |
비긴어게인
|
10년 전 | 654 | |
| 7718 |
|
10년 전 | 2499 | |
| 7717 |
잘살아보자
|
10년 전 | 630 | |
| 7716 |
잘살아보자
|
10년 전 | 370 | |
| 7715 |
잘살아보자
|
10년 전 | 409 | |
| 7714 |
잘살아보자
|
10년 전 | 442 | |
| 7713 | 10년 전 | 1746 | ||
| 7712 | 10년 전 | 1681 | ||
| 7711 | 10년 전 | 1067 | ||
| 7710 | 10년 전 | 1349 | ||
| 7709 | 10년 전 | 1482 | ||
| 7708 | 10년 전 | 1434 | ||
| 7707 | 10년 전 | 820 | ||
| 7706 |
별지기천사
|
10년 전 | 548 | |
| 7705 | 10년 전 | 1047 | ||
| 7704 |
ICONdesignstudio
|
10년 전 | 589 | |
| 7703 | 10년 전 | 552 | ||
| 7702 |
|
10년 전 | 686 | |
| 7701 | 10년 전 | 1384 | ||
| 7700 | 10년 전 | 1079 | ||
| 7699 | 10년 전 | 562 | ||
| 7698 | 10년 전 | 1108 | ||
| 7697 | 10년 전 | 5119 | ||
| 7696 | 10년 전 | 608 | ||
| 7695 | 10년 전 | 1651 | ||
| 7694 | 10년 전 | 1019 | ||
| 7693 | 10년 전 | 1514 | ||
| 7692 | 10년 전 | 1252 | ||
| 7691 | 10년 전 | 783 | ||
| 7690 | 10년 전 | 1360 | ||
| 7689 | 10년 전 | 979 | ||
| 7688 | 10년 전 | 559 | ||
| 7687 |
파랑새1597
|
10년 전 | 555 | |
| 7686 | 10년 전 | 803 | ||
| 7685 | 10년 전 | 1321 | ||
| 7684 | 10년 전 | 772 | ||
| 7683 | 10년 전 | 1018 | ||
| 7682 | 10년 전 | 899 | ||
| 7681 | 10년 전 | 621 | ||
| 7680 | 10년 전 | 959 | ||
| 7679 | 10년 전 | 455 | ||
| 7678 | 10년 전 | 696 | ||
| 7677 | 10년 전 | 597 | ||
| 7676 |
|
10년 전 | 915 | |
| 7675 |
|
10년 전 | 1118 | |
| 7674 | 10년 전 | 1030 | ||
| 7673 | 10년 전 | 727 | ||
| 7672 | 10년 전 | 1057 | ||
| 7671 | 10년 전 | 851 | ||
| 7670 | 10년 전 | 608 | ||
| 7669 |
mashmellow
|
10년 전 | 1202 | |
| 7668 | 10년 전 | 680 | ||
| 7667 | 10년 전 | 962 | ||
| 7666 |
senseme
|
10년 전 | 626 | |
| 7665 | 10년 전 | 478 | ||
| 7664 | 10년 전 | 1870 | ||
| 7663 |
mixx애교
|
10년 전 | 954 | |
| 7662 | 10년 전 | 990 | ||
| 7661 |
hkhkah
|
10년 전 | 755 | |
| 7660 | 10년 전 | 1039 | ||
| 7659 |
커네드커네드
|
10년 전 | 909 | |
| 7658 |
바람돌이팡
|
10년 전 | 639 | |
| 7657 | 10년 전 | 1133 | ||
| 7656 | 10년 전 | 1544 | ||
| 7655 | 10년 전 | 954 | ||
| 7654 |
개발짜증나
|
10년 전 | 833 | |
| 7653 |
네이비칼라
|
10년 전 | 867 | |
| 7652 |
밥먹고합시다
|
10년 전 | 784 | |
| 7651 |
플라이SINJI
|
10년 전 | 1486 | |
| 7650 |
개발짜증나
|
10년 전 | 1379 | |
| 7649 | 10년 전 | 431 | ||
| 7648 |
이미영ㅇㅇ
|
10년 전 | 837 | |
| 7647 | 10년 전 | 409 | ||
| 7646 | 10년 전 | 775 | ||
| 7645 | 10년 전 | 2275 | ||
| 7644 | 10년 전 | 794 | ||
| 7643 |
|
10년 전 | 2837 | |
| 7642 | 10년 전 | 1490 | ||
| 7641 | 10년 전 | 1109 | ||
| 7640 |
개발짜증나
|
10년 전 | 452 | |
| 7639 |
|
10년 전 | 791 | |
| 7638 |
개발짜증나
|
10년 전 | 1095 | |
| 7637 | 10년 전 | 1515 | ||
| 7636 | 10년 전 | 2881 | ||
| 7635 | 10년 전 | 1660 | ||
| 7634 | 10년 전 | 1824 | ||
| 7633 | 10년 전 | 2296 | ||
| 7632 | 10년 전 | 3895 | ||
| 7631 |
|
10년 전 | 1506 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기