新手 php 获取目录上的子目录文件

WBOY
Release: 2016-06-13 13:12:54
Original
1029 people have browsed it

新手求助 php 获取目录下的子目录文件?
代码如下:

C/C++ code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php function enum_file($dir_name)             
{   
  $od = opendir($dir_name);      //打开目录,返回连接号
  while(false != $name = readdir($od))   //读取目录
  {      
    $file_path = $dir_name.'/'.$name;  

    //////以下是调试语句
    echo "file_path is:".$file_path."<br>"; 
    //////以上是调试语句
         
    if (is_file($file_path))   //是文件
    {  
       echo "子目录的文件是".$file_path.<br>;   
    } 
    else //是子目录
    {
        if( ($name !='.')&&($name !='..') )    //输出$name看看就知道
        {
            enum_file($file_path);   //递归的调用 
        }
    }
  }
  closedir($dir_name); 
}

//调用
    $dir=$_SERVER['DOCUMENT_ROOT']."/test";
    enum_file($dir);
?>


Copy after login



在网站test 目录下有 a_test子目录 其中的文件是1.txt.
为什么无法输出 1.txt的全路径名?



------解决方案--------------------
那你都输出了什么?
------解决方案--------------------
给出你运行结果和你想要的结果,说明差别。
------解决方案--------------------
警告:closedir():提供的参数不是一个有效的目录资源
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!