【问题标题】:read zip archive from php://从 php:// 读取 zip 存档
【发布时间】: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


    【解决方案1】:

    我发现了这个: Extract a file from a ZIP string

    我不得不承认,从 php:// 中读取可能是不可能的

    我通过创建临时文件解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      相关资源
      最近更新 更多