php scandir()不显示文件-仅显示目录 [英] php scandir() not showing files - only showing directories

查看:300
本文介绍了php scandir()不显示文件-仅显示目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目录结构如下:

/文件
/files/001
/files/001/addfile.php
/files/002
/files/002/deletefile.php
/files/003
/files/003/viewfile.php

/files
/files/001
/files/001/addfile.php
/files/002
/files/002/deletefile.php
/files/003
/files/003/viewfile.php

我的脚本:

My script:

error_reporting(E_ALL);
$directory      = 'files';
$files      = scandir($directory);

$xml = new DOMDocument('1.0', 'UTF-8');
$xmlFiles = $xml->appendChild($xml->createElement('FILES'));
if(is_dir($directory)) {
    print_r($files);
}
/*foreach($files as $file => $key) {
    if($file == '.' || $file == '..') { continue; }
    echo '$file: '.$file;
    if(is_dir("$directory/$file")) {
        $xmlDir->appendChild($xml->createElement($file));
    }
    else {
        $xmlFiles->appendChild($xml->createElement('FILE', $file));
    }
}*/
echo $xml->saveXML();

我的问题:print_r($files)输出:

数组( [0] =>. [1] => .. [2] => 001 [3] => 002 [4] => 003)

Array ( [0] => . [1] => .. [2] => 001 [3] => 002 [4] => 003 )

scandir为什么只输出目录而不输出文件?

How come scandir only outputs the directories and not the files?

TIA, 内特

推荐答案

Scandir无法递归工作.它只扫描输入到其中的路径.

Scandir does not work recursively. It only scans the path input into it.

Scandir递归函数可深入扫描文件系统

这篇关于php scandir()不显示文件-仅显示目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆