데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 679 | ||
| 7629 |
|
10년 전 | 2437 | |
| 7628 | 10년 전 | 816 | ||
| 7627 |
|
10년 전 | 1053 | |
| 7626 |
|
10년 전 | 1806 | |
| 7625 | 10년 전 | 742 | ||
| 7624 | 10년 전 | 751 | ||
| 7623 |
|
10년 전 | 3137 | |
| 7622 | 10년 전 | 753 | ||
| 7621 |
leeleeleelee
|
10년 전 | 608 | |
| 7620 | 10년 전 | 556 | ||
| 7619 | 10년 전 | 524 | ||
| 7618 | 10년 전 | 1060 | ||
| 7617 | 10년 전 | 740 | ||
| 7616 | 10년 전 | 680 | ||
| 7615 | 10년 전 | 744 | ||
| 7614 | 10년 전 | 1286 | ||
| 7613 |
|
10년 전 | 2102 | |
| 7612 | 10년 전 | 1184 | ||
| 7611 | 10년 전 | 1447 | ||
| 7610 |
|
10년 전 | 1925 | |
| 7609 |
|
10년 전 | 1381 | |
| 7608 |
mwdkim
|
10년 전 | 1154 | |
| 7607 |
|
10년 전 | 1084 | |
| 7606 |
mwdkim
|
10년 전 | 3960 | |
| 7605 | 10년 전 | 708 | ||
| 7604 | 10년 전 | 1045 | ||
| 7603 | 10년 전 | 1664 | ||
| 7602 |
|
10년 전 | 1097 | |
| 7601 |
AniNest
|
10년 전 | 2812 | |
| 7600 |
port443
|
10년 전 | 1056 | |
| 7599 | 10년 전 | 964 | ||
| 7598 | 10년 전 | 1042 | ||
| 7597 | 10년 전 | 4590 | ||
| 7596 |
SeungYeon
|
10년 전 | 912 | |
| 7595 |
untitled
|
10년 전 | 2460 | |
| 7594 |
프로그래머7
|
10년 전 | 1750 | |
| 7593 |
untitled
|
10년 전 | 2393 | |
| 7592 |
untitled
|
10년 전 | 1958 | |
| 7591 |
untitled
|
10년 전 | 2695 | |
| 7590 |
아리마2001
|
10년 전 | 873 | |
| 7589 | 10년 전 | 1125 | ||
| 7588 |
|
10년 전 | 2940 | |
| 7587 | 10년 전 | 1323 | ||
| 7586 | 10년 전 | 687 | ||
| 7585 | 10년 전 | 1724 | ||
| 7584 | 10년 전 | 1424 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1193 | |
| 7582 |
|
10년 전 | 1151 | |
| 7581 | 10년 전 | 1382 | ||
| 7580 | 10년 전 | 1033 | ||
| 7579 |
|
10년 전 | 624 | |
| 7578 | 10년 전 | 1444 | ||
| 7577 |
|
10년 전 | 1891 | |
| 7576 | 10년 전 | 1402 | ||
| 7575 |
멋진남자임
|
10년 전 | 1483 | |
| 7574 | 10년 전 | 2147 | ||
| 7573 | 10년 전 | 3283 | ||
| 7572 | 10년 전 | 781 | ||
| 7571 |
|
10년 전 | 798 | |
| 7570 |
|
10년 전 | 1345 | |
| 7569 | 10년 전 | 1568 | ||
| 7568 |
this1mg
|
10년 전 | 1067 | |
| 7567 |
|
10년 전 | 785 | |
| 7566 | 10년 전 | 930 | ||
| 7565 |
Angel하늘
|
10년 전 | 1035 | |
| 7564 |
seoldi
|
10년 전 | 1279 | |
| 7563 |
|
10년 전 | 1418 | |
| 7562 |
멋진남자임
|
10년 전 | 2119 | |
| 7561 | 10년 전 | 739 | ||
| 7560 |
leeleeleelee
|
10년 전 | 934 | |
| 7559 | 10년 전 | 5073 | ||
| 7558 |
RinaP
|
10년 전 | 812 | |
| 7557 |
|
10년 전 | 1272 | |
| 7556 | 10년 전 | 1214 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1681 | |
| 7554 | 10년 전 | 1111 | ||
| 7553 |
senseme
|
10년 전 | 1362 | |
| 7552 |
ehdltdoit
|
10년 전 | 1457 | |
| 7551 |
|
10년 전 | 1846 | |
| 7550 |
leeleeleelee
|
10년 전 | 1618 | |
| 7549 | 10년 전 | 2448 | ||
| 7548 | 10년 전 | 1857 | ||
| 7547 |
멋진남자임
|
10년 전 | 1980 | |
| 7546 | 10년 전 | 1023 | ||
| 7545 |
ILMare1003
|
10년 전 | 1315 | |
| 7544 |
|
10년 전 | 1270 | |
| 7543 | 10년 전 | 903 | ||
| 7542 | 10년 전 | 682 | ||
| 7541 |
울라라라우
|
10년 전 | 885 | |
| 7540 | 10년 전 | 1609 | ||
| 7539 | 10년 전 | 958 | ||
| 7538 |
|
10년 전 | 1848 | |
| 7537 | 10년 전 | 3635 | ||
| 7536 |
Gaumi
|
10년 전 | 1445 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1299 | |
| 7534 |
senseme
|
10년 전 | 1222 | |
| 7533 | 10년 전 | 1223 | ||
| 7532 | 10년 전 | 891 | ||
| 7531 | 10년 전 | 2081 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기