# Is there any way to "live zip" all files on a site.



## StumpedTechy (Jul 7, 2004)

Okay I have an issue. I have a website that has a ton of files that get downloaded VERY frequently. Once a month (or longer if I forget) I zip up the files into specific resolutions for people to download the entire zip. What I would like to do is have a way for a person to click on a link and have it "live zip" all CURRENT files on the site in any of the subfolders on the site. Is there any way to do this?

Example - This is not the content but just an example using file names and pathing to see what I am trying to accomplish.

Home.com has a number of links to Home.com\zips\1.zip Home.com\zips\2.zip Home.com\zips\3.zip and so on.
All of the zips are all from files on the site such as 1.zip is from Home.com\pictures\picture1640x480.bmp and Home.com\pictures1\picture2640x480.bmp and Home.com\pictures3\picture3640x480.bmp
2.zip is Home.com\pictures\picture1800x600.bmp and Home.com\pictures1\picture2800x600.bmp and Home.com\pictures3\picture1800x600.bmp

I figure instead of rerunning a zip script every month to create new zip file to replace the current 1.zip 2.zip and so on as I place a new file on there have some way the link does some kind of "live archive" and then downloads them all. This would eliminate my monthly activity and keep it always updated no matter if 1 new file is out there or 80 new files.


----------



## JiminSA (Dec 15, 2011)

You may want to look into *php cURL* to achieve this
*Here's an SO example*


----------



## JiminSA (Dec 15, 2011)

StumpedTechy said:


> What I would like to do is have a way for a person to click on a link and have it "live zip" all CURRENT files on the site in any of the subfolders on the site. Is there any way to do this?


Having thought some more, you may get better guidance from _*this SO thread*_, which shows you how to code a zip routine (in PHP).
In essence, you would have the link on which your user clicks, perform a zip of selected directories and then download them


----------



## JiminSA (Dec 15, 2011)

JiminSA said:


> perform a zip of selected directories and then download them


or more clearly ...
"and then download the newly created zip file"


----------



## oitconz (Feb 22, 2018)

That's a lot of over head on your web server - both cpu (zip deflation and compression calcs) and disk reads (all files ) which will get worse over time. 

Alternative one: what is a better option is to set up a scheduled task to run every x minutes, checking for new files whose datetimestamp is greater than lastCheckedDateTime and add them to the zip rather than creating the zip on the fly every time. 

Modern OS / file systems run a semi database type index so it isn't as if it has to scan all folder manually - it should be quite efficient doing it that way.

Alternative two: When user clicks on link, scan for files created after lastUpdateDateTime Stamp, add them to the archive and hand it to the user. The check is not triggered on a schedule but on demand by a user.

Both options avoid all the overhead of newly creating zip, compressing files and updating. 7Zip, linux zip and tar variants all support Update options.


----------

