Forum Moderators: coopster
$handle=opendir('/');echo "<strong>Directories:</strong><br>";
while($file=readdir($handle)) {
if(is_dir($file))
echo "<a href='file_browser.inc.php?dir=$file'>".$file."</a><br>";
}rewinddir($handle);
echo "<br>";echo "<strong>Files:</strong><br>";
while($file=readdir($handle)) {
if(is_file($file))
echo $file."<br>";
}closedir($handle);
?>
while($file=readdir($handle)) {
To:
while(false!== ($file = readdir($handle))) {
in both places that it appears.
"Please note the fashion in which readdir()'s return value is checked in the examples below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see Comparison Operators for more information) FALSE since otherwise, any directory entry whose name evaluates to FALSE will stop the loop (e.g. a directory named "0")."
As mentioned here:
[php.net...]
display.php?dir=dir_name
then grab that data by using $_GET['dir_name']
However, I should warn you that if the application has permissions outside of the web root, it will give them a list of whatever directory they enter.
For example, someone could manually type in:
display.php?dir=path_to_system_files
So you'll have to find some way of validating it. For example, you could check the name, make sure it has no slashes, etc. Then, make sure the directory exists in the restricted directory before opening it.