0

I have an application that wants to serve the contents of a series of relatively small ZIP files at a URL in my application but I do not want to unzip the files to some temporary location and serve them from the temporary location. If I have a file called test123.zip which contains two files hello.png and world.png, I want the following URLs to work:

For each request, I will read the ZIP file and extract the requested content and serve it.

There are lots of constraints that make it so extracting once and serving from disk is less than ideal for my application which is a homework grading and annotation system. Users will be uploading 1000's of limited size ZIPs per day and each ZIP might be read 3 times max and each zip will be discarded in 3-4 days. There is strict authorization on who can see each ZIP file and the contents of that ZIP file. That is a lot of churn in some temporary space where I UNZIP and temporarily hold the files. I would rather not build a bunch of infrastructure to do clean up if I don't have to. And I don't want to fill up my temporary space if possible. And this runs in a multi-server load balanced environment and I don't want to go through the effort of making my temporary space an S3 bucket or networked drive...

So, lets leave the assertion that I should not do this out of the answers. I am looking for a library that helps me do this in PHP or even a practice that could handle this. I have already started to write it - I just wish I could use a library instead.

drchuck
  • 4,415
  • 3
  • 27
  • 30
  • 1
    ZIPArchive cannot be used in memory. Unzip to a new folder in the temp location, and delete the folder after serving. see here https://stackoverflow.com/questions/7391969/in-memory-download-and-extract-zip-archive – delboy1978uk Feb 24 '20 at 15:55
  • It shouldn't be difficult to do the extract/serve/delete for the ZIP contents and it probably will not create a lot of churn as you call it. There will be activity to be sure but, based on your numbers, not really that much that you would need to worry about it (unless the server is under powered). – Dave Feb 24 '20 at 16:49

0 Answers0