Question

How to zip files in the spaces (bucket)?

Posted October 1, 2018 605 views
DigitalOceanUbuntu 16.04

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.

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.

×
1 answer

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.

Submit an Answer