Jump to content

[SOLVED] Directory Listing


jonoc33

Recommended Posts

I recently wrote an upload script, and along with it when you uploaded it a directory listing script shows the files in the uploaded folder.

 

<?PHP 

$folder = "files/upload/"; 
$handle = opendir($folder); 

# Making an array containing the files in the current directory: 
while ($file = readdir($handle)) 
{ 
    $files[] = $file; 
} 
closedir($handle); 

#echo the files 
foreach ($files as $file) { 
    echo "-<a href=$folder$file>$file</a>"."<br />"; 
} 
?> 

That is the directory listing script.

 

Although.. when it shows the files it comes up with these dots eg:

 

Uploaded Files -..

-Picture.gif

-.

-Blah.doc

 

Anyone know as to why these dots would show up?

 

Link to comment
https://forums.phpfreaks.com/topic/73074-solved-directory-listing/
Share on other sites

The "." is the UNIX shorthand for "this directory" and the ".." is the UNIX shorthand for the previous directory. To eliminate them use:

<?php
while (false !== ($file = readdir($handle)))
    if ($file != '.' && $file != '..')
       $files[] = $file; 
?>

 

Ken

 

The "." is the UNIX shorthand for "this directory" and the ".." is the UNIX shorthand for the previous directory. To eliminate them use:

<?php
while (false !== ($file = readdir($handle)))
    if ($file != '.' && $file != '..')
       $files[] = $file; 
?>

 

Ken

 

 

Thankyou. That worked.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.