외부 이미지 저장

· 9년 전 · 2790

[code]

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 "";

[/code]

 

allow_url_fopen 막힌 곳도 잘 됩니다. 

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
PHP 9년 전 조회 2,453
PHP 9년 전 조회 2,251
PHP 9년 전 조회 4,651
PHP 9년 전 조회 2,918
PHP 9년 전 조회 2,234
PHP 9년 전 조회 2,653
PHP 9년 전 조회 2,365
PHP 9년 전 조회 2,764
PHP 9년 전 조회 2,276
PHP 9년 전 조회 2,673
PHP 9년 전 조회 2,378
PHP 9년 전 조회 2,496
PHP 9년 전 조회 2,293
PHP 9년 전 조회 2,683
PHP 9년 전 조회 2,791
PHP 9년 전 조회 3,393
PHP 9년 전 조회 2,514
PHP 9년 전 조회 2,534
PHP 9년 전 조회 2,512
PHP 9년 전 조회 2,902
PHP 9년 전 조회 2,461
PHP 9년 전 조회 2,145
PHP 9년 전 조회 5,353
PHP 9년 전 조회 2,105
PHP 9년 전 조회 2,243
PHP 9년 전 조회 2,274
기타 9년 전 조회 3,080
PHP 9년 전 조회 2,435
PHP 9년 전 조회 2,597
PHP 9년 전 조회 3,002