php infinite traversal folder sample sharing
- 2021-01-25 07:19:53
- OfStack
Recently, in the php directory operation, there is 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.
We also use for, if, GET, and that's about it:
Here's the code:
<?php
if(isset($_GET['id']))// Determine whether to pass a value
{
$s=str_replace(' ','+',$_GET['id']);
$s=base64_decode($s);// Accept the passed value value 1 Is the absolute path strength of the directory to be opened
chdir($s);// Switch to the directory you want to open
}
$a=opendir('.');// Open the current directory
while(false!==($c=readdir($a)))// The file name that loops over the contents of the directory
{
if(is_dir($c))// Determine whether it is a directory or a file
{
if($c=='.')
{
}
else
{
if($c=='..')
{
$w=base64_encode(substr(getcwd(),0,strrpos(getcwd(),'\\')));// The current path plus the directory name Is the absolute path to the directory
echo " on 1 level "."<a href='6.php?id=$w'> Open the </a><br />";// Pass the absolute path that will be opened when you click Open with chdir Switch to the directory you want to open
}else
{
$w=base64_encode(getcwd().'\\'.$c);// The current path plus the directory name Is the absolute path to the directory
echo "$c"."<a href='6.php?id=$w'> Open the </a><br />";// Pass the absolute path that will be opened when you click Open with chdir Switch to the directory you want to open
}
}
}
else
{
echo "$c Not a directory <br />";
}
}
?>