Home > Backend Development > PHP Tutorial > php递归列出所有文件和目录的代码_php技巧

php递归列出所有文件和目录的代码_php技巧

WBOY
Release: 2016-05-17 09:35:10
Original
728 people have browsed it

/*我的程序在国外的SREVER上,自己编的程序存放到哪,我很难记清。
所以编了一个简单的目录递归函数,查看我的程序,很方便的。
*/
function tree($directory)
{
$mydir=dir($directory);
echo "

    ";
    while($file=$mydir->read()){
    if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){
    echo "
  • $file
  • ";
    tree("$directory/$file");
    }else{
    echo "
  • $file
  • ";
    }
    }
    echo "
";
$mydir->close();
}
//start the program
echo "

目录为粉红色

";
tree(".");
?>
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