Home  >  Article  >  Backend Development  >  php check what files are in the directory

php check what files are in the directory

angryTom
angryTomOriginal
2019-10-29 16:13:272101browse

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=&#39;color:#666&#39;>(".date("Y-m-d H:i:s",$fmt).")</span> ".$filePath."<br/>";
}
closedir($dh);
}
}
?>

Effect:

php check what files are in the directory

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!

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