根据文件保存日期从网页下载文件

时间:2016-09-10 21:17:29

标签: javascript php html forms

我在网络开发方面还很新,我需要一些建议。我正忙着创建一个带日期选择器的页面,然后我有一个文件夹,每天保存一个文件。我要做的是:用户需要选择他想要的文件的日期并单击下载,并且需要下载该日期保存的文件。有人可以告诉我如何让这个工作。我已经尝试过使用JavaScript和php的一些东西,但无法获得可行的解决方案。

1 个答案:

答案 0 :(得分:0)

此代码应该可以胜任。 首先,我们扫描提供的路径并列出所有文件,然后检查创建日期并找到我们的目标文件。

<?php

$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;
        break;
    }
}

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