问题
I am downloading this photo using function: file_get_contents(), and it seems to be corrupted. But original photo looks fine.
Original photo: original photo
Downloaded photo: Download photo
Code:
$current = file_get_contents($image);
$name = '/tmp/img/' . uniqid().".jpg";
file_put_contents($name, $current);
$tmpImages[] = $name;
回答1:
Try this.
function savephoto($urlpath,$savepath)
{ //Download images from url
$in = fopen($urlpath, "rb");
$out = fopen($savepath, "wb");
while ($chunk = fread($in,8192))
{
fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
}
savephoto('http://i.stack.imgur.com/pwMiA.jpg','newname.jpg');
来源:https://stackoverflow.com/questions/37030224/file-get-contents-jpg-corrupt-download