我使用Zend HttpClient的下载zip文件,并获得分配给一个变量为这样的文件的内容:可以打开下载的压缩文件,而不必先将它保存为文件?
$body = $response->getBody();
$body
有一个zip文件的内容,可以将其打开不保存它作为一个文件第一,使用http://php.net/manual/en/class.ziparchive.php或其他5.2本地类?
编辑的建议,提出了一些很好的想法如何可以未做临时文件是可行的,但由于我需要使用代理服务器适配器已经,去创建一个的长度自己的适配器的目的,只是不值得。
我结束了使用tmpname创建一个tmp文件(这是我想避免的,但最终在这里结束了)。
if ($response->isSuccessful()){
$tmpfile = tempnam(sys_get_temp_dir(),'Insight');
if ($tmpfile!==false){
$handle = fopen($tmpfile, "w");
if (fwrite($handle, $response->getBody())!==false){
$zip = new ZipArchive;
if ($zip->open($tmpfile) === TRUE) {
echo $zip->getFromIndex(0);
$zip->close();
} else {
$this->errorLog('Unable to open zip file '.$tmpfile);
}
}else{
$this->errorLog('Unable to write to temporary file '.$tmpfile);
}
fclose($handle);
}else{
$this->errorLog('Unable to create temporary zip file in '.sys_get_temp_dir());
}
}else{
$this->errorLog('Unable to download url '.$insightUrl);
}
你就不能使用'zip_open( “http://url/to/download.zip”)'? – 2011-06-01 08:27:46
@Jules需要使用代理,并且可能必须使用cookie。不要说这可能无法用你的方式完成,但如果我仍然可以使用zend http客户端,肯定会更容易。 – Niklas 2011-06-01 08:29:15