Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8170251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:05:46+00:00 2026-06-06T21:05:46+00:00

I have a page on a training site which displays several downloads whose ids

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:05:46+00:00Added an answer on June 6, 2026 at 9:05 pm

    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:

    /*Functions*/
    
    //Convert url to absolute path
    function url2path($url){
        $parsed = parse_url($url);
        if(!is_array($parsed)) return false;
        $path = $_SERVER['DOCUMENT_ROOT'].$parsed['path'];
        return $path;
    }
    //Returns the highest number (works with Unix Timestamps)
    function get_highest_number($numbers){
        if(!is_array($numbers)) return false;
        $highest = $numbers[0];
        foreach($numbers as $number) if($highest < $number) $highest = $number;
        return $highest;
    }
    
    $dtimes = array();
    foreach($dl as $d) { //iterate through my array of downloads
        $dtimes[] = filemtime(url2path($d->filename));
        //$dtimes is an array containing all the unix timestamps of my downloads
        //other code to display individual downloads, etc
    }
    
    //Zip Details
    $uploads = wp_upload_dir();
    $parent = get_page($post->post_parent);
    $zip_url = $uploads[baseurl].'/downloads/zips/'.$parent->post_name.'_'.$post->post_name.'.zip';
    
    if($dtimes){
        $latesttime = get_highest_number($dtimes); //latest UNIX timestamp of files
        //If ZIP already exists, get timestamp of when ZIP was created
        //I create the ZIP file name from the page title and store them all in 1 directory, thus, I would have to know the full zip filename to retrieve it.
        if($ziptime = filemtime(url2path($zip_url))){   
            $zip = new ZipArchive(); 
            $zip->open(url2path($zip_url));
    
            //If ZIP timestamp is more recent than file, show ZIP
            if($ziptime > $latesttime && $zip->numFiles == count($dtimes)) $result = url2path($zip_url);
            else $result = cat has create_zip($downloads,$zip_url,true);    
        }
    //If ZIP doesn't exist or ZIP timestampe is less recent than files, create/rewrite ZIP
        else $result = create_zip($downloads,$zip_url,true);
        //regardless of what has happened, $result should now hold the path to the zip archive.
    }
    

    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/)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have page which is redirected from htaccess. now I can pass the German
I have page where I use model which can have different types (depending by
I have page named page--news.tpl.php, which i created for my news page. But after
I have page (Default1.aspx) in which I am redirecting to another page (Default2.aspx) using
I have Page Tab App, which has a landing page with a Log In
I have 100 training, lecture, guide video files which has size 30MB to 1GB
Greetings, all. I'm working on a training project; I have a page for user
I have implemented JQuery FullCalendar by fetching the events dynamically from an aspx page.
I'm witnessing a very strange phenomenon on one page (http://can.org.uk/training/training-diary) on our wp site.
I'm trying to fire off several HTTP requests from an ASP.NET page. The page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.