데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7430 |
|
11년 전 | 4945 | |
| 7429 | 11년 전 | 1776 | ||
| 7428 |
멋진남자임
|
11년 전 | 1165 | |
| 7427 |
sdflksdj2
|
11년 전 | 825 | |
| 7426 | 11년 전 | 1362 | ||
| 7425 | 11년 전 | 1388 | ||
| 7424 | 11년 전 | 1052 | ||
| 7423 |
SeungYeon
|
11년 전 | 561 | |
| 7422 | 11년 전 | 810 | ||
| 7421 |
sdflksdj2
|
11년 전 | 684 | |
| 7420 | 11년 전 | 968 | ||
| 7419 |
|
11년 전 | 1398 | |
| 7418 |
멋진남자임
|
11년 전 | 1429 | |
| 7417 | 11년 전 | 607 | ||
| 7416 |
senseme
|
11년 전 | 1227 | |
| 7415 | 11년 전 | 961 | ||
| 7414 | 11년 전 | 711 | ||
| 7413 | 11년 전 | 4847 | ||
| 7412 | 11년 전 | 4405 | ||
| 7411 |
holla
|
11년 전 | 895 | |
| 7410 | 11년 전 | 4249 | ||
| 7409 | 11년 전 | 3927 | ||
| 7408 | 11년 전 | 4270 | ||
| 7407 | 11년 전 | 5080 | ||
| 7406 | 11년 전 | 4729 | ||
| 7405 | 11년 전 | 4302 | ||
| 7404 | 11년 전 | 760 | ||
| 7403 | 11년 전 | 5678 | ||
| 7402 | 11년 전 | 1517 | ||
| 7401 |
|
11년 전 | 975 | |
| 7400 | 11년 전 | 2973 | ||
| 7399 |
멋진남자임
|
11년 전 | 915 | |
| 7398 |
파랑새1597
|
11년 전 | 2699 | |
| 7397 | 11년 전 | 2271 | ||
| 7396 |
basketball
|
11년 전 | 1370 | |
| 7395 | 11년 전 | 1611 | ||
| 7394 | 11년 전 | 931 | ||
| 7393 | 11년 전 | 2069 | ||
| 7392 | 11년 전 | 848 | ||
| 7391 |
잘살아보자
|
11년 전 | 5363 | |
| 7390 |
잘살아보자
|
11년 전 | 2226 | |
| 7389 |
잘살아보자
|
11년 전 | 3321 | |
| 7388 |
파랑새1597
|
11년 전 | 931 | |
| 7387 | 11년 전 | 1107 | ||
| 7386 |
프리랜서퍼블리셔
|
11년 전 | 973 | |
| 7385 | 11년 전 | 1569 | ||
| 7384 |
울라라라우
|
11년 전 | 891 | |
| 7383 | 11년 전 | 1553 | ||
| 7382 |
잘살아보자
|
11년 전 | 4224 | |
| 7381 |
잘살아보자
|
11년 전 | 1998 | |
| 7380 |
잘살아보자
|
11년 전 | 1943 | |
| 7379 |
잘살아보자
|
11년 전 | 5904 | |
| 7378 |
senseme
|
11년 전 | 1899 | |
| 7377 |
잘살아보자
|
11년 전 | 2748 | |
| 7376 | 11년 전 | 2415 | ||
| 7375 |
잘살아보자
|
11년 전 | 1048 | |
| 7374 |
잘살아보자
|
11년 전 | 3159 | |
| 7373 |
잘살아보자
|
11년 전 | 2481 | |
| 7372 |
잘살아보자
|
11년 전 | 5832 | |
| 7371 |
잘살아보자
|
11년 전 | 3466 | |
| 7370 |
잘살아보자
|
11년 전 | 1914 | |
| 7369 |
잘살아보자
|
11년 전 | 2173 | |
| 7368 |
ksdhtm56
|
11년 전 | 571 | |
| 7367 | 11년 전 | 1434 | ||
| 7366 | 11년 전 | 933 | ||
| 7365 | 11년 전 | 3544 | ||
| 7364 |
잘살아보자
|
11년 전 | 1396 | |
| 7363 |
잘살아보자
|
11년 전 | 1370 | |
| 7362 |
잘살아보자
|
11년 전 | 1503 | |
| 7361 | 11년 전 | 3595 | ||
| 7360 | 11년 전 | 3561 | ||
| 7359 | 11년 전 | 3377 | ||
| 7358 |
멋진남자임
|
11년 전 | 1027 | |
| 7357 | 11년 전 | 3414 | ||
| 7356 | 11년 전 | 2601 | ||
| 7355 | 11년 전 | 3188 | ||
| 7354 |
파랑새1597
|
11년 전 | 649 | |
| 7353 |
잘살아보자
|
11년 전 | 2427 | |
| 7352 |
잘살아보자
|
11년 전 | 2413 | |
| 7351 |
잘살아보자
|
11년 전 | 2474 | |
| 7350 |
잘살아보자
|
11년 전 | 1476 | |
| 7349 |
잘살아보자
|
11년 전 | 1967 | |
| 7348 |
잘살아보자
|
11년 전 | 1284 | |
| 7347 |
잘살아보자
|
11년 전 | 1081 | |
| 7346 |
멋진남자임
|
11년 전 | 1647 | |
| 7345 | 11년 전 | 992 | ||
| 7344 | 11년 전 | 3874 | ||
| 7343 | 11년 전 | 3657 | ||
| 7342 | 11년 전 | 1286 | ||
| 7341 | 11년 전 | 2517 | ||
| 7340 |
|
11년 전 | 934 | |
| 7339 | 11년 전 | 1736 | ||
| 7338 | 11년 전 | 3346 | ||
| 7337 | 11년 전 | 3661 | ||
| 7336 | 11년 전 | 4597 | ||
| 7335 | 11년 전 | 977 | ||
| 7334 | 11년 전 | 1534 | ||
| 7333 | 11년 전 | 2937 | ||
| 7332 |
|
11년 전 | 1109 | |
| 7331 |
KeePin뽁이
|
11년 전 | 1104 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기