列出显示index.php的文件夹中的文件

编程入门 行业动态 更新时间:2024-10-05 17:20:46
本文介绍了列出显示index.php的文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个代码,但它正在显示index.php本身如何过滤* .php文件?

I have this code, but it is showing the index.php itself How can I filter *.php files?

<?php if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $thelist .= '<LI><a href="'.$file.'">'.$file.'</a>'; } } closedir($handle); } ?> <P>Dir:</p> <UL> <P><?=$thelist?></p> </UL>

还有一种方法可以通过修改或创建时间对它们进行排序?

Also is there a way to sort them by modification or creation time?

推荐答案

另一个使用 ksort 或 krsort 功能(测试)。 (见代码中的注释)

Here's another that uses ksort or krsort functions (tested). (See comments in code.)

<?php // you can add to the array $ext_array = array(".htm", ".php", ".asp", ".js"); //list of extensions not required $dir1 = "."; $filecount1 = 0; $d1 = dir($dir1); while ($f1 = $d1->read()) { $fext = substr($f1,strrpos($f1,".")); //gets the file extension if (in_array($fext, $ext_array)) { //check for file extension in list continue; }else{ if(($f1!= '.') && ($f1!= '..')) { if(!is_dir($f1)) $filecount1++; $key = filemtime($f1); $files[$key] = $f1 ; } } } // use either ksort or krsort => (reverse order) //ksort($files); krsort($files); foreach ($files as $f1) { $thelist .= '<LI><a href="'.$f1.'">'.$f1.'</a>'; } ?> <P>Dir:</p> <UL> <P><?=$thelist?></p> </UL>

更多推荐

列出显示index.php的文件夹中的文件

本文发布于:2023-11-02 06:29:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   夹中   index   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!