【发布时间】:2015-11-19 08:05:52
【问题描述】:
我从 Web 服务 (WSDL) 接收大对象。他们的位置之一是将 zip 的文件内容存储为 base64 字符串。我需要从这个 zip 中读取文件名和内容。
这是我写的:
$ePackageFile = $ePackage->ePackageFile;
$attachment = $this->mapper->mapEPackageFileData((array)$ePackageFile, false);
$limitMBs = 20 * 1024 * 1024;//20MB LIMIT !
$fp = fopen("php://temp/maxmemory:$limitMBs", 'r+');
fwrite($fp, base64_decode($attachment['attachment_fileContent']));
$zip = new ZipArchive;
$handler = $zip->open("php://temp");
if($handler === FALSE)
return array('status'=>false, 'result'=>'failed to get stream');
$i=0;
$out = array();
while (($file = $zip->getNameIndex($i)) && $file !== false) {
$out[] = array('filename' => $zip->getNameIndex($i), 'content' => $zip->getFromIndex($i));
$i++;
}
$zip->close();
但我仍然有“警告:ZipArchive::getNameIndex(): Invalid or unialized Zip object ...”
我还使用以下方法检查了文件:
$fp = fopen('test.zip','a+');
fwrite($fp, base64_decode($attachment['attachment_fileContent']));
fclose($fp);
然后使用 KEKA 提取它(成功)。
您能帮我使用包装器阅读内容吗?
编辑: 我收到错误代码 11(无法打开文件)。
【问题讨论】:
标签: php ziparchive