0
我试图将图像下载到一个ZipArchive,从通过其API一个社交网站,我用下面的代码:使用cURL图像下载到ZipArchive
...
public function downloadAlbumZip($album_name, $photos)
{
$zip = new ZipArchive();
$album_name = $this->_cleanAlbumName($album_name);
$filename = 'album.zip';
$file = tempnam(PHOTOS, "{$album_name}-").'.zip';
if ($zip->open($file, ZIPARCHIVE::CREATE) === TRUE)
{
foreach ($photos as $photo) {
$image = $photo['pid'] . '.jpg';
$binary = $this->_getImage($photo['src']);
$zip->addFromString($image, $binary);
}
$output = print_r($zip, true);
$zip->close();
exit('Zip Saved.<br /><a href="javascript:history.go(-1);">Back to Album Overview</a>');
} else {
die('Zip Failed.');
}
}
private function _getImage($img)
{
if (function_exists('curl_init'))
{
$ch = curl_init($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$rawdata = curl_exec($ch);
curl_close($ch);
return $rawdata;
}
}
...
哪些工作,但很速度慢并且经常以超时错误结束,任何人都可以推荐一种方法来加快速度?
感谢