首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >显示添加到网站目录的最新文件,同时排除PHP中的某些特定文件

显示添加到网站目录的最新文件,同时排除PHP中的某些特定文件
EN

Stack Overflow用户
提问于 2018-05-31 07:43:41
回答 1查看 43关注 0票数 1

我在网上找到了这段代码,它非常有用。我已经尝试了几个小时来调整它,以排除某个文件名(mobile.htm)。在显示结果之前,我是否可以获得一些正确方向的帮助以排除mobile.htm文件名,以及如何显示文件的完整路径,以便将其转换为链接?

代码语言:javascript
运行
复制
<?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;}阻止请求显示您输入的特定文件。

代码语言:javascript
运行
复制
<?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下面的帮助我。我非常喜欢这个网站和社区。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50614749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档