외부 이미지 저장

· 9년 전 · 2694

[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,360
PHP 9년 전 조회 2,150
PHP 9년 전 조회 4,559
PHP 9년 전 조회 2,832
PHP 9년 전 조회 2,133
PHP 9년 전 조회 2,579
PHP 9년 전 조회 2,277
PHP 9년 전 조회 2,685
PHP 9년 전 조회 2,184
PHP 9년 전 조회 2,569
PHP 9년 전 조회 2,275
PHP 9년 전 조회 2,395
PHP 9년 전 조회 2,215
PHP 9년 전 조회 2,571
PHP 9년 전 조회 2,695
PHP 9년 전 조회 3,298
PHP 9년 전 조회 2,404
PHP 9년 전 조회 2,425
PHP 9년 전 조회 2,413
PHP 9년 전 조회 2,797
PHP 9년 전 조회 2,362
PHP 9년 전 조회 2,058
PHP 9년 전 조회 5,241
PHP 9년 전 조회 2,016
PHP 9년 전 조회 2,136
PHP 9년 전 조회 2,179
기타 9년 전 조회 2,988
PHP 9년 전 조회 2,341
PHP 9년 전 조회 2,493
PHP 9년 전 조회 2,909
🐛 버그신고