file_get_contents jpg损坏下载 [英] file_get_contents jpg corrupt download
本文介绍了file_get_contents jpg损坏下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用函数:file_get_contents()下载此照片,它似乎已损坏。但原始照片看起来不错。
I am downloading this photo using function: file_get_contents(), and it seems to be corrupted. But original photo looks fine.
原始照片:
原始照片
已下载的照片:
下载照片
代码:
$current = file_get_contents($image);
$name = '/tmp/img/' . uniqid().".jpg";
file_put_contents($name, $current);
$tmpImages[] = $name;
推荐答案
试试这个。
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');
这篇关于file_get_contents jpg损坏下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文