Home > Backend Development > PHP Tutorial > php traverses sub-files under a folder

php traverses sub-files under a folder

WBOY
Release: 2016-08-08 09:18:55
Original
1074 people have browsed it
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 introduces PHP to traverse the sub-files under a folder, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template