Php infinite traversal folder example sharing _ PHP Tutorial

Source: Internet
Author: User
Php infinite traversal folder example sharing. Recently, I was able to perform a php Directory operation and made an infinite directory traversal. the functions used are: isset () to determine whether a variable defines chdir () and change the current directory to the specified directory. Opend has recently been able to perform php directory operations and has made a directory infinite traversal:

The following functions are used:

Isset () determines whether a variable is defined

Chdir () changes the current directory to the specified directory.

Open the opendi () directory.

Readdir () reads the directory.

Getcwd () to get the current directory.

We also use for if GET to transfer the value about these things:

The following code is used:

The code is as follows:


If (isset ($ _ GET ['id']) // determines whether to pass the value
{
$ S = str_replace ('', '+', $ _ GET ['id']);
$ S = base64_decode ($ s); // The passed value is generally the absolute path strength of the directory to be opened.
Chdir ($ s); // switch to the directory to be opened
}
$ A = opendir ('.'); // open the current directory
While (false! ==( $ C = readdir ($ a) // cyclically traverses the file name of the directory content
{
If (is_dir ($ c) // you can determine whether a directory or a file is used.
{
If ($ c = '.')
{
}
Else
{
If ($ c = '..')
{
$ W = base64_encode (substr (getcwd (), 0, strrpos (getcwd (), '\'); // add the directory name to the current path to indicate the absolute path of the Directory.
Echo "upper-level". "Open
"; // When you click open, the absolute path to be opened is passed out. use chdir to switch to the directory to be opened.
} Else
{
$ W = base64_encode (getcwd (). '\'. $ c); // add the directory name to the current path to indicate the absolute path of the Directory.
Echo "$ c". "Open
"; // When you click open, the absolute path to be opened is passed out. use chdir to switch to the directory to be opened.
}
}
}
Else
{
Echo "$ c is not a directory
";
}
}

?>

Isset () determines whether a variable defines chdir () to change the current directory to the specified directory. Opend...

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.