3

I'm retrieving a zip-Archive via a SOAP call in PHP. Is there a way to extract the content without writing it to a file first? So far all I found seemed to rely on storing the data in a local file, extract the content and delete the file again which seems superfluous to me.

  • if it is not compressed, then it should be possible. but if it is compressed, then you have to decompress it to a file – Fender Jul 21 '11 at 09:02
  • Perhaps you can use the `zip://` stream. Not exactly sure how it works, as I've never used it, but you can probably find out for yourself. – nikc.org Jul 21 '11 at 09:05
  • @nick Unless I'm wrong, the `zip://` wrapper is only useful to open an entry from a ZIP file transparently from ZIP-unaware functions like `fopen()` and it definitively requires a file. – Álvaro González Jul 21 '11 at 09:08
  • Please see this question as well: [Zip Stream in PHP](http://stackoverflow.com/questions/3078266/zip-stream-in-php) – hakre Jul 21 '11 at 09:39

1 Answers1

0

There are PHP classes that use gzuncompress functions for zip decompression. I think they can take zip file inside a string and if not you can adapt the code to your purposes.

This is an example of one such class (code from here under LGPL, requires registration).

hakre
  • 178,314
  • 47
  • 389
  • 754
Kamil Szot
  • 15,477
  • 6
  • 53
  • 62
  • the direct way? or do they use files in one step? – Fender Jul 21 '11 at 09:05
  • Tested this class, it does not work with a zip I've created. Additionally you need to modify it to deal with streams more properly. – hakre Jul 21 '11 at 09:58
  • Too bad. Nevertheless I'd be looking around for something like that. I once used similar class with good results on server where zip php extension was not available. – Kamil Szot Jul 21 '11 at 11:00
  • There is a partial solution on http://php.net/manual/en/ref.zip.php in the comment by wdtemp at seznam dot cz (the topmost one). If there is nothing out-of-the-box available one could extend that to a full fledged extractor... I think I will stick to saving the stuff to a file which I delete seconds after that... meh. – Christoph Grimmer-Dietrich Jul 22 '11 at 08:39