Manipulate an Archive in memory with PHP (without creating a temporary file on disk)?

You might be able to use the stream php://temp or php://memory to read and write to/from the archive See php.net/manual/en/wrappers.php.php.

You might be able to use the stream php://temp or php://memory to read and write to/from the archive. See php.net/manual/en/wrappers.php.php.

At the moment, I'm using the php zip extension and writing a tempfile whenever I serve a download. I tried using the php://temp wrapper (figuring that it was superior to php://memory, as with large quantities of data, a tempfile IS a good idea, and hosts might allow its use even while restricting fs access. I ran into the problem that I had to close the zipfile, which appearantly freed everything in php://temp/ .(Reading from the zipfile before and after closing gave me 0 bytes.) Anyway, I don't care about the library I use, as long as it works.

PHP-internal would be preferred, of course. – tkolar Jul 28 '09 at 7:10.

Regarding your comment that php://temp works for you except when you close it, try keeping it open, flushing the output, then rewind it back to 0 and read it. Look here for more examples: us.php.net/manual/en/function.tmpfile.php Also research output buffering and capturing: us.php.net/manual/en/function.ob-start.php.

You need to use ZipArchive::addFromString - if you use addFile() the file is not actually added until you go to close it. (Horrible bug imho, what if you are trying to move files into a zip and you delete them before you close the zip...) addFromString() adds it to the archive immediately.

A lot of processes write temporary files and delete them, and often they never hit the disk due to caching. A tempfile is automatically deleted when closed. That's it's nature.

There are only two ways I can think of to create a zip file in memory and serve it and both are probably more trouble than they are worth. Use a ram disk. Modify the ziparchive class to add a method that does everything the close() method does, except actually close the file.

(Or add a leave-open parameter to close()). This might not even be possible depending on the underlying C libraries.

Php scripts which come with phpmyadmin and are located in the "libraries" directory. This script allows downloading of a zip, without the need of having the files as real files or saving the zip itself as a file. It is a shame that this functionality is not part of a more generic PHP library.

Here is a link to the zip.lib.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions