我仍然是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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句