I have a page on a training site which displays several downloads whose ids are pulled from a database. At the bottom, I’ve successfully coded to have all of those files compressed into a zip for download.
However, each time the page loads, the zip is recreated and overwrites the previous zip file. As you can imagine, this causes some load time that is less than desirable.
I’m wondering how I can make PHP check to see if any of the files have changed since the last page load (last view opened the page), and if so, then recreate the zip and overwrite.
Looking through PHP docs, it seems filemtime() might have something to do with it, but I have no experience with that and am not even sure I can use it on a website. Looking into it more, I’m fearing I might need to involve caching, which I also have no experience with.
Any help, suggestions or leads would be very helpful. Let me know if I can make more sense or provide any of my existing code as background.
I’m sure the solution provided by Yoda would have worked, but I went for (what I think) a simpler solution.
For my purposes, I needed to keep the zip file names constant over time (couldn’t place the timestamp in the filename). Instead, I gathered the latest timestamp from the files using filemtime(). I then compared those to the timestamp of my zip file. If the zip time was less recent, the zip was nonexistent, or the number of files in the list didn’t match the number in the zip, I recreated the zip, otherwise, I just showed the zip.
My situation is a bit unique as I am storing and displaying the downloadable files via a wordpress plugin (Download Monitor). Here’s basically what I did though:
Hope this can help someone with a similar question. If you’re interested in a demo, almost any page in the ‘Training Library’ utilizes this code (i.e. http://chesapeakestormwater.net/training-library/all-about-stormwater/impervious-cover-and-stream-health/)