php infinite traversal directory example
- 2021-01-11 01:56:26
- 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.
opendir () 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']))
{
$s=$_GET['id'];
chdir($s);
}
echo ' The current in '.getcwd(),'<br />';
$a=opendir('.');
while($c=readdir($a))
{
if(is_dir($c))
{
$w=getcwd().'\\'.$c;
echo $c."<a href='6.php?id=$w'> Open the </a><br />";
}
else
{
echo $c.'<br />';
}
}
?>
If you have any suggestions can be put forward!! Thank you very much!!