2

I receive large object from webservice (WSDL). One of their position is fileContent of zip stored as base64 string. I need to read filename and content from this 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 ... "

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).

Could you help me with read content using wrapper?

Edit: I receive error code 11 (can't open file).

Bartosz Kowalczyk
  • 1,479
  • 2
  • 18
  • 34

1 Answers1

0

I found this: Extract a file from a ZIP string

I have to admit that it's probably impossible to read from php:// like in question

I solve my problem with creating temporary file.

Community
  • 1
  • 1
Bartosz Kowalczyk
  • 1,479
  • 2
  • 18
  • 34