php

php 下载远程图片

Posted by LQ on March 31, 2017

curl方法

$ch=curl_init();
$timeout=5;
curl_setopt($ch,CURLOPT_URL,$imgUrl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$img=curl_exec($ch);
curl_close($ch);

file_get_contents方法

$content = file_get_contents($file_url);
file_put_contents($save_to, $content);

fopen方法

$in=fopen($file_url, "rb");
$out=fopen($save_to, "wb");
while ($chunk = fread($in,8192))
{
   fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);

copy 方法

copy($imgUrl,$localImgName)

还有啥?待补充