使用cURL从外部URL下载映像

时间:2010-11-29 16:01:22

标签: php curl

如何使用cURL从网址下载外部图片?

2 个答案:

答案 0 :(得分:1)

见这里:

http://www.edmondscommerce.co.uk/php/php-save-images-using-curl/

function save_image($img,$fullpath){
 $ch = curl_init ($img);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
 $rawdata=curl_exec($ch);
 curl_close ($ch);
 if(file_exists($fullpath)){
  unlink($fullpath);
 }
 $fp = fopen($fullpath,'x');
 fwrite($fp, $rawdata);
 fclose($fp);
}

其他文章/来源:

http://forums.digitalpoint.com/showthread.php?t=371632

http://www.bitrepository.com/download-image.html

http://php.bigresource.com/Track/php-Jjg3DsKY/

答案 1 :(得分:0)

来自php.net的

- 也读入一个字符串。

   <?php
        // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, CURLOPT_URL, "example.com");

        //return the transfer as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // $output contains the output string
        $output = curl_exec($ch);

        // close curl resource to free up system resources
        curl_close($ch);     
?>