Posted by techusky on 08/06/07 17:20
I have a *very* simple script written that displays the directory
listing of the current working directory, but I am having some
difficulty when I try to change folders. Basically, I have my $dir
variable set to this: --- $dir = getcwd() . "\\" . $nav; --- but for
some reason the script does not actually display the contents of the
directory if you change from the directory the script is located in.
Here is my code if someone is willing to take a quick look to tell me
where I am going wrong:
<?php
// Tell the script which directory to list
$nav = $_GET['nav'];
$dir = getcwd() . "\\" . $nav;
// Open the directory
$dh = opendir($dir) or die("Unable to open $dir");
// Parse the directory listing
// and display this contents
while ($file = readdir($dh))
{
// Do not include the current directory
if ($file != "." && $file != "..")
{
// If the file is not a directory
// add it to the fileArray
if (!is_dir($file))
{
array_push($fileArray, "$file");
}
// If the file is a directory
// add ?nav=$file to the url
if (is_dir($file))
{
echo "<a href=\"listing.php?nav=$file\" target=\"_self\">
$file</a><br>";
}
// If the file is a file
// just link to it
if (is_file($file))
{
echo "<a href=\"$nav/$file\" target=\"_self\">$file</
a><br>";
}
}
}
// Close the working directory
closedir($dh);
echo '<br><br>';
echo $nav;
echo '<br><br>';
echo $dir;
echo '<br><br>';
print $_SERVER['REQUEST_URI'];
?>
If you actually test this out, you will notice as I do that if you
change directories by appending ?nav=some_directory to your url, the
$nav and $dir variables *seem* to be properly updated but you will not
get a listing of the contents of the new directory... I'm stumped.
[Back to original message]
|