Cindi Liebenberg Cindi Liebenberg - 1 month ago 4x
HTML Question

Download a file from a webpage based on the file saved date

I am still very new at web development, I need some suggestions please. I am busy creating a page with a date selector, then I have a folder with one file saved every day. What I am trying to do is: The user needs to select the date of the file he wants and click download and the file saved on that date needs to be downloaded. Can someone please give me an idea how I can get this to work. I have tried some things with JavaScript and php and could not get a working solution.


This code should do the job. First we scan path provided and list all files, then check creation date and find our target file.


$Path       = './'; // Set path of files here
$TargetDate = '2016-08-11'; // We find the first file with thi date
$TargetFile = null; // Store result here

// Lets Do It

foreach (glob("$Path/*") as $File) {
    $Stat = stat($File);

    if (date("Y-m-d", $Stat['ctime']) == $TargetDate) {
        $TargetFile = $File;

// Your File!
if (is_null($TargetFile)) {
    echo 'No file found';
} else {
    echo $TargetFile;