본문 바로가기

Web/PHP

[PHP] 외부 이미지 저장

반응형

출처 : http://multime.kr/bbs/board.php?bo_table=tech&wr_id=12

function save_web_image($url, $saveName) { if (strstr($url, "//")) { $a = explode("//", $url); $url = $a[1]; } $a = explode("/", $url); $host = $a[0]; $path = ""; for ($i = 1; $i < count($a); $i++) $path .= "/".$a[$i]; $fp = fsockopen($host, 80, $errno, $errstr, 10); if ($fp) { $send = "GET $path HTTP/1.1\r\n"; $send.= "Host: $host\r\n"; $send.= "Connection: Close\r\n\r\n"; fwrite($fp, $send); $content = ""; while (!feof($fp)) $content .= fread($fp, 1024); $content = substr($content, strpos($content, "\r\n\r\n") + 4); fclose($fp); $im = imagecreatefromstring($content); imagegif($im, $saveName); return $saveName; } return ""; }

반응형