我在网上找到了这段代码,它非常有用。我已经尝试了几个小时来调整它,以排除某个文件名(mobile.htm)。在显示结果之前,我是否可以获得一些正确方向的帮助以排除mobile.htm文件名,以及如何显示文件的完整路径,以便将其转换为链接?
<?php
$path = "states";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read())) {
$filepath = "{$path}/{$entry}";
if(is_file($filepath) && filectime($filepath) > $latest_ctime) {
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
echo $latest_filename;
?>更新:这是我为自己工作的代码。我有一个$var,我正试图在一个没有被看到的索引页面上查看它。对我来说起作用的是在主页上制作了一个iframe,它链接到另一个页面,其中包含$var的$_SESSION信息。这是我放在iframe中的代码,它对我有效。
我列出的3 if ($entry == "YourFile.html") {continue;}阻止请求显示您输入的特定文件。
<?php
$path = "states/$ls";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while ($entry = $d->read()) {
if ($entry == "mobile.htm") {continue;}
if ($entry == "bg.jpg") {continue;}
if ($entry == "flag.png") {continue;}
$filepath = "$path/$entry";
$ctime = filectime($filepath);
if (is_file($filepath) && $ctime > $latest_ctime) {
$latest_ctime = $ctime;
$latest_filename = $filepath;
}
}
echo $latest_filename;
?>非常感谢@Barmar下面的帮助我。我非常喜欢这个网站和社区。
https://stackoverflow.com/questions/50614749
复制相似问题