외부 이미지 저장

· 9년 전 · 2674

[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,331
PHP 9년 전 조회 2,122
PHP 9년 전 조회 4,531
PHP 9년 전 조회 2,799
PHP 9년 전 조회 2,105
PHP 9년 전 조회 2,567
PHP 9년 전 조회 2,243
PHP 9년 전 조회 2,672
PHP 9년 전 조회 2,163
PHP 9년 전 조회 2,549
PHP 9년 전 조회 2,252
PHP 9년 전 조회 2,364
PHP 9년 전 조회 2,204
PHP 9년 전 조회 2,541
PHP 9년 전 조회 2,675
PHP 9년 전 조회 3,280
PHP 9년 전 조회 2,382
PHP 9년 전 조회 2,411
PHP 9년 전 조회 2,381
PHP 9년 전 조회 2,774
PHP 9년 전 조회 2,339
PHP 9년 전 조회 2,035
PHP 9년 전 조회 5,220
PHP 9년 전 조회 1,989
PHP 9년 전 조회 2,117
PHP 9년 전 조회 2,157
기타 9년 전 조회 2,970
PHP 9년 전 조회 2,317
PHP 9년 전 조회 2,472
PHP 9년 전 조회 2,888
🐛 버그신고