我曾尝试使用ZipStream,我认为当urls很小时,如5个urls,它工作得很好,但当urls较大时,浏览器会转来转去,我无法获得压缩file.Has有人以前遇到过同样的问题吗?许多thanks.Below是我的代码,我正在使用mac os,并使用本地主机和端口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();发布于 2017-08-08 16:57:44
好的,我已经使用上面的代码成功地从浏览器下载了1.3gzip文件。起初,我无法获得压缩文件,因为我使用的是phpstorm内部解释器,后来我切换到apache服务器并成功。感谢zipstream的作者Jonatan Männchen。
https://stackoverflow.com/questions/45547849
复制相似问题