Home >Backend Development >PHP Tutorial >Example of PHP loop output of all files and folder paths in a specified directory (simple and practical)_PHP tutorial

Example of PHP loop output of all files and folder paths in a specified directory (simple and practical)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:30:04889browse

If you want to build an online file management system, you must first know how to read directories and files. In fact, this function can be implemented with just a few lines of code.

Output effect:

Example of PHP loop output of all files and folder paths in a specified directory (simple and practical)_PHP tutorial

Implementation code:

Copy code The code is as follows:

$dir = "D:/"; ​​//The directory to be obtained
echo "************ Get all files and folders in the directory************ ***
";
//First determine whether the specified path is a folder
if (is_dir($dir)){
if ($dh = opendir($dir )){
while (($file = readdir($dh))!= false){
//The full path of the file name includes the file name
$filePath = $dir.$file;
//Get the file modification time
$fmt = filemtime($filePath);
echo "(".date("Y-m-d H:i:s" ,$fmt).") ".$filePath."
";
}
closedir($dh);
}
}
?>

This is just the most basic effect. Once you understand it, it is easy to make other requirements.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/768129.htmlTechArticleIf you want to build an online file management system, you must first know how to read directories and files. In fact, this function This can be achieved with just a few lines of code. Output effect: Implementation code...
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