Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 遍历文件夹_Php - Fatal编程技术网

Php 遍历文件夹

Php 遍历文件夹,php,Php,我一直在使用我在网上找到的snipit,用我的PHP脚本显示目录中的文件和文件夹。这部分工作正常,但我希望能够单击文件夹并获得一个类似的html页面,显示其内容,并且能够在浏览器中打开文本文件(如果文本文件位于开始目录中,则工作正常) 现在,当我点击一个文件夹时,一个老式的页面打开了,里面没有html文件。唯一的方法是在每个文件夹中创建一个新的PHP脚本并链接到它吗?我尝试使用DirectoryIterator类,但它给了我一个错误。我再也没有DirectoryIterator的狙击手了,但它有

我一直在使用我在网上找到的snipit,用我的PHP脚本显示目录中的文件和文件夹。这部分工作正常,但我希望能够单击文件夹并获得一个类似的html页面,显示其内容,并且能够在浏览器中打开文本文件(如果文本文件位于开始目录中,则工作正常)

现在,当我点击一个文件夹时,一个老式的页面打开了,里面没有html文件。唯一的方法是在每个文件夹中创建一个新的PHP脚本并链接到它吗?我尝试使用DirectoryIterator类,但它给了我一个错误。我再也没有DirectoryIterator的狙击手了,但它有点像“找不到类DirectoryIterator”

以下是我正在使用的代码(正在使用):

$arrayImports=array();
如果($handle=opendir($importLogPath)
{
while(false!=($entry=readdir())
{
印章(记项);
如果($entry!=“$entry!=”))
{
$arrayImports[]=“

”; } } closedir($handle); } arsort($arrayImports); foreach($arrayImports as$value) { 打印“
  • $value
  • ”; }

    谢谢!

    你在找这样的东西吗?

    我在一个老项目中使用了它…它非常酷。你也可以添加ajax来浏览文件夹,而无需刷新页面

    再见

    $arrayImports = array ();
    
    if ($handle = opendir ($importLogPath)
    {
    while (false !== ($entry = readdir ()))
       {
           chop ($entry);
           if ($entry != "."  $entry != "..")
           {
              $arrayImports [] = "<p><a href=$importLogPath$entry target=_blank>$entry</a></p>";
           }
        }
       closedir($handle);
    }
    
    arsort ($arrayImports);
    foreach ($arrayImports as $value)
    {
      print "<li>$value</li>";
    }