0

The PHP documentation offers a simple way to load a ZipArchive from a file like the following:

$zip = new \ZipArchive();
$zip->open('file.zip');

Using an external file storage which is abstracted away means I don't have local files, but only file content to read files. Is there any way to load a ZipArchive from the file content?

Something like

$zip->fromString($fileContent);

Only available solutions found here are converting everything into base64 encoding in between which is to memory intensive for larger files and therefore fails.

Christian Kolb
  • 1,368
  • 2
  • 23
  • 43
  • 2
    Does this answer your question? [Extract a file from a ZIP string](https://stackoverflow.com/questions/15140063/extract-a-file-from-a-zip-string) – M. Eriksson Jul 15 '22 at 08:41
  • Unfortunately not, I found that too, but it's not creating a ZipArchive instance. – Christian Kolb Jul 15 '22 at 09:03
  • _"but it's not creating a ZipArchive instance"_ - Did you read the accepted answer? It contains `$zip = new ZipArchive;` which does exactly that, creating a ZipArchive instance. – M. Eriksson Jul 15 '22 at 09:06
  • You're right, I focused onto the wrong answer (most upvoted) to answer your comment. The problem of the other solution is that it's base64 encoded which needs too much memory for larger files. But I haven't defined that as part of the question and will update it. – Christian Kolb Jul 15 '22 at 09:36

0 Answers0