This program implements the use of an index. php file to achieve the traversal of all folders, avoiding the need to infinitely copy index. php to the folder to achieve the effect of the following is the core file:
Index. php file
The code is as follows:
Header ('content-Type: text/html charset: utf-8 ');
Date_default_timezone_set ('prc ');
$ RootDir = 'listfile'; // the root directory of the site to load all files of the program.
// Site base_url setting method:
// Considering the versatility, Method 2 is used by default. when modifying the method, you must modify the. htaccess file at the same time.
// Method 1: Set the site directory as the root directory
// Corresponds to. htaccess:
// # RewriteBase/
// $ Base_url = 'http: // www.listfile.com /';
// Method 2: Set the site subdirectory as the root directory
// Corresponds to. htaccess:
// RewriteBase/listFile/
$ Base_url = 'http: // www.test.com/'. $ rootDir .'/';
// Parse the folder path
If (empty ($ _ GET ['Return ']) {
$ Dir = '.';
} Else {
$ Dir = trim (array_pop (explode ($ rootDir, $ _ GET ['Return ']),'/');
If (empty ($ dir) $ dir = '.';
Else $ dir = './'. $ dir;
}
// Echo $ dir; // Current Folder
// Traverse the current folder
$ Pattern = '*'; // '*' searches for all files, which can be intelligently matched, such *. jpg search for jpg files ,*. {jpg, png} Searches for jpg and png files, case sensitive !!
$ Skip = '*. skip'; // exclude. skip type File (corresponding to "skipped output file. "), you can modify it yourself, such *. exclude all php files in php
$ Files = scandir_through ($ dir, $ pattern, $ skip, false );
?>
List Files