Home > Article > Backend Development > php check what files are in the directory
php Check what files are in the directory
php Check what files are in the directory You can use opendir to open the path, and then use Just read the content and output it with readdir.
<?php $dir = "D:/"; //要获取的目录 echo "********** 获取目录下所有文件和文件夹 ***********<hr/>"; //先判断指定的路径是不是一个文件夹 if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh))!= false){ //文件名的全路径 包含文件名 $filePath = $dir.$file; //获取文件修改时间 $fmt = filemtime($filePath); echo "<span style='color:#666'>(".date("Y-m-d H:i:s",$fmt).")</span> ".$filePath."<br/>"; } closedir($dh); } } ?>
Effect:
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of php check what files are in the directory. For more information, please follow other related articles on the PHP Chinese website!