Forum Moderators: coopster

Message Too Old, No Replies

displaying contents of dir, with link to file(s)

i have a code snippet from php.net i cant get it to work 100%

         

yt404

2:00 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



below is the snippet that is in a file called "show.php" it works fine it displays the contents with links, however whenever i click one of the links it just opens up a list of the contents of the dir in a new window.

can anyone help me out and tell me why it isnt actually showing the files.. gifs, jpegs etc?

//heres the code

<?
$the_array = Array();
$handle = opendir('/home/www/juttuffi/midi');
while (false!== ($file = readdir($handle))) {
if ($file!= "." && $file!= "..") {
$the_array[] = $file;
}
}
closedir($handle);
sort ($the_array);
reset ($the_array);
while (list ($key, $val) = each ($the_array)) {
echo "<a href=show.php?id=$val target=_blank>$val</a><br>";
}
?>

coopster

1:39 am on Jun 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, yt404!

The reason you keep getting the the same listing is because you keep calling the same script,

show.php
, which is designed to give the directory listing at the beginning of the script in your
opendir
function.

If you want to show the actual file, drop the

show.php
from your href and give it the actual (http) path to the file.

yt404

12:32 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



cheers mate, i got it sorted now