How to zip files in the spaces (bucket)?

My website is made in laravel (PHP framework). There are a set of files which I need to zip and give to the user at run time.

So, one user uploads a bunch of files and another user shows up to download them. I need to zip and set the download. Can you please tell me if there’s any command which I can run via PHP code.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

It depends on how often this is called and how intricate you want to make it.

A simple solution would be to download those files through PHP to a local temporary directory. Then you would issue a gzip command on the commandline which you can do through the PHP system() function. After the file is created you can then send that file to the user.

Reading in the output and returning that along with the proper headers to specify the format.

After the file has been received you can then clean out that directory. You can either have the file deleted in PHP after the transfer is complete, or you can setup a crontab on that directory to delete any files that are over “x” amount of time old. Depending on the size of the zip files and how long it takes transfer you can set them to be deleted every 24 hours or so forth.