我使用下面的代碼將圖像從url複製到我的web目錄的功能,但我不知道爲什麼有些圖像不能100%複製。從url複製後不是精確的圖像複製
這裏是我的web目錄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);
}
}
我也試過,捲曲,但它仍然無法正常複製一些圖片。
捲曲代碼:
$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);
雖然不只是file_put_contents而不是fopen/fwrite? – 2013-02-14 21:45:04
您可能只需指定「wb +」作爲標誌。 b表示二進制模式。這可能是原因。它可能認爲它是一個文本文件。 – 2013-02-14 21:46:52
「wb +」和file_put_contents不起作用到 – Marek 2013-02-14 22:16:24