Home > Article > Backend Development > PHP infinite directory traversal code example
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. "; 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
|