Recently in the ability to PHP directory operations, engaged in a directory infinite traversal:
The functions used are:
Isset () Determines whether a variable is defined
ChDir () changes the current directory to the specified directory.
Opendi () opens the directory.
Readdir () reads the directory.
GETCWD () Gets the current directory.
I also used a for if get pass value about these things:
Here's the code:
Copy Code code as follows:
<?php
if (Isset ($_get[' id '))//To determine whether to pass the value
{
$s =str_replace (', ' + ', $_get[' id '));
$s =base64_decode ($s);//Accept passed value values are generally the absolute strength of the directory to open
ChDir ($s);//switch to the directory you want to open
}
$a =opendir ('. '); /Open Current Directory
while (false!== $c =readdir ($a))//loops through the file name of the contents of the directory
{
if (Is_dir ($c))//Judge is a directory or a file
{
if ($c = = '. ')
{
}
Else
{
if ($c = = ' ... ')
{
$w =base64_encode (substr (GETCWD (), 0,strrpos (GETCWD (), ' \ "))//current path plus directory name is the absolute path to the directory
echo "Upper level". <a href= ' 6.php?id= $w ' > Open </a><br/> '////When clicked on the absolute path to open will be passed out with chdir switch to the directory to open
}else
{
$w =base64_encode (GETCWD). ' \ $c);//current path plus directory name is the absolute path of the directory
echo "$c". <a href= ' 6.php?id= $w ' > Open </a><br/> '////When clicked on the absolute path to open will be passed out with chdir switch to the directory to open
}
}
}
Else
{
echo "$c is not a directory <br/>";
}
}
?>