'; foreach($list as $file){ $target = "$dir/$file"; ..."/> '; foreach($list as $file){ $target = "$dir/$file"; ...">

Home  >  Article  >  Backend Development  >  PHP file traversal

PHP file traversal

巴扎黑
巴扎黑Original
2016-11-12 11:21:371114browse

$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);

Statement:
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
Previous article:PHP file lock writeNext article:PHP file lock write