简体   繁体   English

从php://读取zip存档

[英]read zip archive from php://

I receive large object from webservice (WSDL). 我从Web服务(WSDL)收到大对象。 One of their position is fileContent of zip stored as base64 string. 他们的位置之一是存储为base64字符串的zip的fileContent。 I need to read filename and content from this zip. 我需要从该zip文件中读取文件名和内容。

I wrote this: 我这样写:

$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();

But I still have "Warning: ZipArchive::getNameIndex(): Invalid or unitialized Zip object ... " 但是我仍然有“警告:ZipArchive :: getNameIndex():无效或统一的Zip对象...”

I also checked file using: 我还使用以下方法检查了文件:

$fp = fopen('test.zip','a+');
fwrite($fp, base64_decode($attachment['attachment_fileContent']));
fclose($fp);

And then extract it using KEKA (successful). 然后使用KEKA(成功)将其提取。

Could you help me with read content using wrapper? 您能帮我用包装纸阅读内容吗?

Edit: I receive error code 11 (can't open file). 编辑:我收到错误代码11(无法打开文件)。

I found this: Extract a file from a ZIP string 我发现了这一点: 从ZIP字符串中提取文件

I have to admit that it's probably impossible to read from php:// like in question 我不得不承认,可能无法从php://中读取问题

I solve my problem with creating temporary file. 我通过创建临时文件解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM