PHP infinite directory traversal code example

WBOY
Release: 2016-07-25 08:45:54
Original
957 people have browsed it
In PHP development, we often encounter various problems. Today, I want to achieve infinite traversal of directories in PHP, but it is difficult to implement this method. After searching some information on the Internet, I can achieve unlimited traversal in PHP. The table of contents is not that difficult, just take a look at it now.
The functions used are:
isset() to determine whether a variable is defined
chdir() to change the current directory to the specified directory.
opendir() opens a directory.
readdir() reads a directory.
getcwd(). Get the current directory.
I also used for if GET to pass the value, which is about these things:
The following is the code:
if(isset($_GET['id']))//Determine whether to pass the value
{
$s=str_replace(' ','+',$_GET['id']);
$s=base64_decode($s);//The value accepted is generally the directory to be opened Absolute road strength
chdir($s);//Switch to the directory to be opened
}
$a=opendir('.');//Open the current directory
while(false!==($c =readdir($a)))//Loop through the file names of the directory contents
{           
                                                                                                                                                                        ')
                                                                                                                                                  )
                                                                                                                                                                           ​, '\')))))); // The current path plus the directory name is the absolute path of the directory
echo "." & Lt; a href = '6.php? ID = $ w' & gt; ;/a>
";//When you click to open, pass the absolute path to be opened. Use chdir to switch to the directory to be opened. wd( ). '\'. $ C); // The current path plus the directory name is the absolute path of the directory
echo "$ c". "& lt; a href = '6.php? ID = $ w' & gt; open
";//When you click to open, pass the absolute path to be opened. Use chdir to switch to the directory you want to open.
               else
                                                     
                                                                                                         echo "$c is not a directory
"; The path must be an absolute path, don't make a mistake, I hope it can help everyone.
Recommended reading: The first secondary packaging of mongo
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!