Home > Backend Development > PHP Tutorial > PHP gets all files in a folder (recursive algorithm)

PHP gets all files in a folder (recursive algorithm)

怪我咯
Release: 2023-03-12 18:04:01
Original
1486 people have browsed it

The following editor will bring you a simple example of the recursive algorithm for php to obtain all files in a folder. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

is as follows:

function my_scandir($dir)
{
$files=array();
if(is_dir($dir))
{
if($handle=opendir($dir))
{
while(($file=readdir($handle))!==false)
{
if($file!="." && $file!="..")
{
if(is_dir($dir."/".$file))
{
$files[$file]=my_scandir($dir."/".$file);
}
else
{
$files[]=$dir."/".$file;
}
}
}
closedir($handle);
return $files;
}
}
}
Copy after login

The above is the detailed content of PHP gets all files in a folder (recursive algorithm). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template