我曾尝试使用ZipStream,我认为当网址像5个网址一样小时,效果很好,但是当网址较大时,浏览器会四处转转,我无法获取zip文件。以前有人遇到过同样的问题吗?非常感谢.Below是我的代码。我正在使用mac os并使用localhost和端口63342在phpstorm上调试代码。
<?php
require_once __DIR__ . '/vendor/autoload.php';
use ZipStream\ZipStream;
// Create new Zip
$zip = new ZipStream("hi.zip");
// add a lot of http urls
$urls = [
'http://img31.mtime.cn/pi/2014/10/22/092931.12614666_1000X1000.jpg',
'http://img31.mtime.cn/pi/2014/10/22/092931.79193700_1000X1000.jpg',
];
foreach($urls as $url) {
// Create Temp File
$fp = tmpfile();
// Download File
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
// Force to write all data
fflush($fp);
// Rewind to the beginning, otherwise the stream is at the end from the start
rewind($fp);
// Find out a file name from url
// In this case URL
http://img31.mtime.cn/pi/2014/10/22/092931.12614666_1000X1000.jpg will yield
// /pi/2014/10/22/092931.12614666_1000X1000.jpg as file path
$filename = parse_url($url, PHP_URL_PATH);
// Add File
$zip->addFileFromStream($filename, $fp);
// Close the Temp File
fclose($fp);
}
// Finish ZIP
$zip->finish();
答案 0 :(得分:0)
好吧,我已经使用上面的代码从浏览器中成功下载了1.3G zip文件。起初,我无法获取zip文件,因为我使用phpstorm内部解释器,后来我改为apache服务器并成功。感谢zipstream的作者JonatanMännchen。