Single index. php implements PHP folder traversal at any level (original Zjmainstay) _ php instance

Source: Internet
Author: User
Tags glob
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.