You are here: Re: Custom directory listing and $_GET question « PHP Programming Language « IT news, forums, messages
Re: Custom directory listing and $_GET question

Posted by techusky on 08/06/07 17:26

On Aug 6, 10:20 am, techu...@gmail.com wrote:
> 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.

Oh, something I forgot to include: I also tried setting the $dir
variable to: $dir = getcwd() . "/" . $nav; but that seemed to make no
difference.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация