How to traverse folders and file lists in php PHP directory traversal example code

WBOY
Release: 2016-07-25 08:46:36
Original
916 people have browsed it
Share several PHP codes for traversing directories and files, a PHP class for traversing directories and file lists, and provide a calling instance of this PHP directory class, which can be used to obtain a list of directories and files under relative paths or absolute paths.

How to traverse folder and file list in php?

PHP class for traversing directories and file lists, with usage examples.

Code:

Copy code Code example: getDir( $Dir ); if( $DirFileArray ){ foreach( $DirFileArray['DirList'] as $Handle ){ $File = $Dir.DS.$Handle; $DirFileArray['FileList'][$Handle] = $this->getFile( $File ); } } }else{ $DirFileArray[] = '[Path]:''.$Dir.'' is not a dir or not found!'; } return $DirFileArray; } } ?>

Example: (relative path or absolute path)

1, php gets directory list

Copy code Code example: getDir( $Dir_dir ); print_r($getDir); ?>

2, php gets file list

Copy code Code example: getFile( $File_one_dir ); $getFile_two = $getDirFile->getFile( $File_two_dir ); print_r($getFile_one); print_r($getFile_two); ?>

3, php gets directory/file list

Copy code Code example: getDirFile( $Dir_dir ); print_r($getDirFile); ?>


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!