Home >Backend Development >PHP Tutorial >php code to list all files in a directory

php code to list all files in a directory

WBOY
WBOYOriginal
2016-07-25 08:58:22815browse
This article introduces how to use php code to list all files in the directory. Friends in need can refer to it.

The code is as follows:

<?php
/**
* 列出目录中所有文件
* edit bbs.it-home.org
*/
$current_dir = 'F:/www/';  
$dir = opendir($current_dir);  
  
echo "direcotry list:<ul>";  
  
while(false !== ($file=readdir($dir))){  
    if($file != "." && $file != ".."){  
        echo "<li>$file</li>";  
    }  
}  
  
echo "</ul>";  
closedir($dir);
?>

The above code was tested under windows. If it is the same drive letter as the web, just write: $current_dir='/www/';.



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