치

외부 이미지 저장

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

[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-13 조회 2,887
PHP 17-01-12 조회 2,416
PHP 17-01-12 조회 2,681
PHP 17-01-12 조회 2,585
PHP 17-01-11 조회 2,883
PHP 17-01-11 조회 2,629
PHP 17-01-11 조회 2,506
PHP 17-01-10 조회 2,554
PHP 17-01-10 조회 2,294
PHP 17-01-10 조회 2,408
PHP 17-01-10 조회 4,076
PHP 17-01-09 조회 4,659
PHP 17-01-09 조회 3,362
PHP 17-01-09 조회 2,740
PHP 17-01-08 조회 4,624
PHP 17-01-08 조회 2,731
PHP 17-01-08 조회 2,568
PHP 17-01-07 조회 4,944
PHP 17-01-07 조회 3,219
PHP 17-01-06 조회 2,536
PHP 17-01-06 조회 2,969
PHP 17-01-06 조회 2,707
PHP 17-01-06 조회 3,081
PHP 17-01-05 조회 2,600
PHP 17-01-05 조회 2,957
PHP 17-01-05 조회 2,649
PHP 17-01-04 조회 2,816
PHP 17-01-04 조회 2,578
PHP 17-01-04 조회 2,992
PHP 17-01-04 조회 3,083