치즈버거

외부 이미지 저장

· 2017-01-04 (수) 00:45:07 · 3128

[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 막힌 곳도 잘 됩니다. 

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

개발자팁

5,404건

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

+
분류 제목 글쓴이 날짜 조회
PHP 17-01-04 조회 3,129
PHP 17-01-03 조회 3,757
PHP 17-01-03 조회 2,863
PHP 17-01-03 조회 2,862
PHP 17-01-03 조회 2,852
PHP 17-01-02 조회 3,243
PHP 17-01-02 조회 2,778
PHP 17-01-02 조회 2,503
PHP 17-01-02 조회 5,740
PHP 17-01-01 조회 2,470
PHP 17-01-01 조회 2,610
PHP 17-01-01 조회 2,594
기타 16-12-31 조회 3,422
PHP 16-12-30 조회 2,750
PHP 16-12-30 조회 2,980
PHP 16-12-30 조회 3,380
PHP 16-12-29 조회 3,077
PHP 16-12-29 조회 3,567
PHP 16-12-29 조회 3,028
PHP 16-12-28 조회 2,634
PHP 16-12-28 조회 2,974
PHP 16-12-28 조회 3,082
PHP 16-12-27 조회 5,608
PHP 16-12-27 조회 3,043
PHP 16-12-27 조회 2,644
PHP 16-12-26 조회 3,261
PHP 16-12-26 조회 2,603
PHP 16-12-26 조회 2,682
PHP 16-12-23 조회 4,032
PHP 16-12-23 조회 2,807