我正在使用带有以下代码的函数将图像从 url 复制到我的 web 目录,但我不知道为什么有些图像没有 100% 复制。
这是我的网页目录中错误图像的副本http://www.aligatoor.pl/uploads/deals/2632b3802e8ed7abe83788dab605bbf7.jpg
这里是原始图像http://infobuzer.pl/img/r4d3k/voucher/50e35a84c9038.jpg
function upload_file($file_path)
{
$deal_img_data=file_get_contents($file_path);
$file_name=md5($file_path).".jpg";
if(!file_exists($file_name))
{
$file=fopen($file_name,"w+");
fwrite($file,$deal_img_data);
}
}
我也尝试过使用 CURL,但它仍然无法正确复制一些图像。
卷曲代码:
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
$saveto=md5($url).".jpg";
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);