Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.