Home > Backend Development > PHP Tutorial > PHP file traversal

PHP file traversal

巴扎黑
Release: 2016-11-21 11:56:24
Original
1529 people have browsed it

$dir = "D:\workspace";
function list_file($dir = '.'){
    $list = scandir($dir);
    echo &#39;<ol>&#39;;
    foreach($list as $file){
        $target = "$dir/$file";
        if ( is_dir($target) && $file != &#39;.&#39; && $file != &#39;..&#39; ){
            echo "<li style=\"color:red;font-weight:bold;\">$file</li>";
            list_file($target);
        } else if ( $file != &#39;.&#39; && $file != &#39;..&#39;){
            echo "<li>$file</li>";
        }
    }
    echo &#39;</ol>&#39;;
}
list_file($dir);
Copy after login

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