치즈버거

외부 이미지 저장

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

[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,403건

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

+
분류 제목 글쓴이 날짜 조회
PHP 17-01-03 조회 3,729
PHP 17-01-03 조회 2,841
PHP 17-01-03 조회 2,843
PHP 17-01-03 조회 2,833
PHP 17-01-02 조회 3,221
PHP 17-01-02 조회 2,761
PHP 17-01-02 조회 2,483
PHP 17-01-02 조회 5,714
PHP 17-01-01 조회 2,453
PHP 17-01-01 조회 2,587
PHP 17-01-01 조회 2,572
기타 16-12-31 조회 3,405
PHP 16-12-30 조회 2,728
PHP 16-12-30 조회 2,957
PHP 16-12-30 조회 3,355
PHP 16-12-29 조회 3,057
PHP 16-12-29 조회 3,546
PHP 16-12-29 조회 3,006
PHP 16-12-28 조회 2,606
PHP 16-12-28 조회 2,951
PHP 16-12-28 조회 3,056
PHP 16-12-27 조회 5,578
PHP 16-12-27 조회 3,021
PHP 16-12-27 조회 2,627
PHP 16-12-26 조회 3,246
PHP 16-12-26 조회 2,586
PHP 16-12-26 조회 2,660
PHP 16-12-23 조회 4,011
PHP 16-12-23 조회 2,784
PHP 16-12-23 조회 3,679