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

PHP gets all files in a folder (recursive algorithm)

怪我咯
怪我咯Original
2017-07-05 10:24:521393browse

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;
}
}
}

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!

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