我在web开发方面还很新,我需要一些建议。我正忙着创建一个带有日期选择器的页面,然后我有一个每天保存一个文件的文件夹。我要做的是:用户需要选择他想要的文件的日期,然后单击下载,保存在该日期的文件需要下载。有人能给我一个主意,我怎么能得到这个工作。我已经尝试了一些事情与JavaScript和php,无法得到一个工作的解决方案。
这段代码应该可以完成这项工作。首先,我们扫描提供的路径并列出所有文件,然后检查创建日期并找到我们的目标文件。
<?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;
}