PHP根据图片路径下载图片
$path = 'd:/images/';
if (!file_exists($path)) {
if (mkdir($path, 0777, true)) {
$img = "http://lmcjl.com/567571/9b838948a0e2c13f.jpg";
ob_clean();
ob_start();
readfile($img);
<span style = "white-space:pre;"> </span>//读取图片
$img = ob_get_contents();
<span style = "white-space:pre;"> </span>//得到缓冲区中保存的图片
ob_end_clean();
<span style = "white-space:pre;"> </span>//清空缓冲区
$fp = fopen($path.'test.jpg', 'w');
<span style = "white-space:pre;"> </span>//写入图片
if (fwrite($fp, $img)) {
fclose($fp);
echo "图片保存成功";
}
}
}
如果有多个图片需要保存,需要清空缓冲区来保证每个图片的准确性。