-1

I have this dynamic data in PHP, but for each array record, I want to allow a downloadable option to save a zip archive of all records (each as a separate file).

These are actually DNS zone records that are housed in a database. It wouldn't make much sense if they're in a single text file, so I'm looking to somehow have the data exported as separate files inside the zip.

I could save them to disk, but know there's a way in PHP to use the headers to force a download of data as a certain filetype. What I don't know is how to zip that data on the fly. Maybe I can't, and will have to save each to a temp folder, then zip the contents of that folder, then delete the contents after downloaded.

Thought maybe the community might have an idea of where to start. Thanks!

1

You'll want to look at using the Zip module that's available in PHP (more specifically, the ZipArchive class). You'll need to use this class to generate the Zip file itself.

After generating the zip file, you would be able to use a combination of readfile(), and the sending of a Content-Type header of application/zip.

It should be a simple case of unlink()'ing the file after the readfile() function call to be able to remove the generated zip file. I'm not sure whether this would interrupt the transfer to the client though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.