데모
<?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개
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 430 | 19년 전 | 4097 | ||
| 429 | 19년 전 | 3297 | ||
| 428 | 19년 전 | 4132 | ||
| 427 | 19년 전 | 3467 | ||
| 426 | 19년 전 | 3101 | ||
| 425 | 19년 전 | 3403 | ||
| 424 | 19년 전 | 2438 | ||
| 423 | 19년 전 | 2861 | ||
| 422 | 19년 전 | 2348 | ||
| 421 | 19년 전 | 3707 | ||
| 420 | 19년 전 | 4736 | ||
| 419 | 19년 전 | 3793 | ||
| 418 |
|
19년 전 | 1742 | |
| 417 | 19년 전 | 2744 | ||
| 416 | 19년 전 | 2388 | ||
| 415 | 19년 전 | 2606 | ||
| 414 | 19년 전 | 4409 | ||
| 413 |
|
19년 전 | 2596 | |
| 412 | 19년 전 | 3046 | ||
| 411 |
|
19년 전 | 2994 | |
| 410 |
|
19년 전 | 3682 | |
| 409 |
|
19년 전 | 3632 | |
| 408 |
|
19년 전 | 1855 | |
| 407 | 19년 전 | 2226 | ||
| 406 | 19년 전 | 2781 | ||
| 405 | 19년 전 | 2443 | ||
| 404 | 19년 전 | 4299 | ||
| 403 | 19년 전 | 3301 | ||
| 402 |
NeoGenesis
|
19년 전 | 4088 | |
| 401 | 19년 전 | 2606 | ||
| 400 |
|
19년 전 | 2493 | |
| 399 | 19년 전 | 2955 | ||
| 398 | 19년 전 | 2484 | ||
| 397 | 19년 전 | 2779 | ||
| 396 | 19년 전 | 2471 | ||
| 395 | 19년 전 | 3176 | ||
| 394 | 19년 전 | 1717 | ||
| 393 | 19년 전 | 2992 | ||
| 392 | 19년 전 | 2249 | ||
| 391 | 19년 전 | 2176 | ||
| 390 | 19년 전 | 2285 | ||
| 389 | 19년 전 | 2644 | ||
| 388 | 19년 전 | 2174 | ||
| 387 | 19년 전 | 4484 | ||
| 386 |
|
19년 전 | 2690 | |
| 385 |
|
19년 전 | 2480 | |
| 384 | 19년 전 | 3009 | ||
| 383 | 19년 전 | 3052 | ||
| 382 | 19년 전 | 3105 | ||
| 381 |
|
19년 전 | 2629 | |
| 380 |
|
19년 전 | 3014 | |
| 379 | 19년 전 | 2548 | ||
| 378 | 19년 전 | 2205 | ||
| 377 | 19년 전 | 2776 | ||
| 376 | 19년 전 | 2468 | ||
| 375 |
|
19년 전 | 2558 | |
| 374 | 19년 전 | 3815 | ||
| 373 | 19년 전 | 3266 | ||
| 372 | 19년 전 | 4985 | ||
| 371 |
세은아빠2
|
19년 전 | 2412 | |
| 370 | 19년 전 | 4496 | ||
| 369 | 19년 전 | 3109 | ||
| 368 | 19년 전 | 2901 | ||
| 367 | 19년 전 | 3722 | ||
| 366 | 19년 전 | 2650 | ||
| 365 | 19년 전 | 3735 | ||
| 364 | 19년 전 | 4009 | ||
| 363 | 19년 전 | 3436 | ||
| 362 | 19년 전 | 3475 | ||
| 361 | 19년 전 | 4106 | ||
| 360 |
hwatta
|
19년 전 | 2360 | |
| 359 | 19년 전 | 5099 | ||
| 358 | 19년 전 | 3654 | ||
| 357 | 19년 전 | 2595 | ||
| 356 |
sdesign1s
|
19년 전 | 2275 | |
| 355 | 20년 전 | 2751 | ||
| 354 | 20년 전 | 3028 | ||
| 353 | 20년 전 | 2789 | ||
| 352 |
|
20년 전 | 5769 | |
| 351 |
|
20년 전 | 2700 | |
| 350 |
|
20년 전 | 4291 | |
| 349 |
hwatta
|
20년 전 | 2180 | |
| 348 | 20년 전 | 7306 | ||
| 347 | 20년 전 | 2412 | ||
| 346 | 20년 전 | 3503 | ||
| 345 | 20년 전 | 4305 | ||
| 344 | 20년 전 | 2643 | ||
| 343 | 20년 전 | 3918 | ||
| 342 | 20년 전 | 3065 | ||
| 341 | 20년 전 | 4087 | ||
| 340 |
|
20년 전 | 5139 | |
| 339 |
|
20년 전 | 4231 | |
| 338 | 20년 전 | 5867 | ||
| 337 | 20년 전 | 2043 | ||
| 336 |
|
20년 전 | 3315 | |
| 335 |
|
20년 전 | 3536 | |
| 334 |
|
20년 전 | 2922 | |
| 333 |
hwatta
|
20년 전 | 2432 | |
| 332 | 20년 전 | 4653 | ||
| 331 | 20년 전 | 2267 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기