Jump to content

PHP directory listing


mattheww

Recommended Posts

What one would like to do is show a particular directory's files, filesize and filetype of each file, I have the first bit where it echo's the filename out, but when I try filesize and filetype, it goes all wrong! I just can't seem to find out whats wrong!

 

I keep getting:

Warning: filetype() [function.filetype]: Lstat failed for Koala.jpg in ... on line 42

 

<?php

$path = "dir/";
$dir_handle = @opendir($path) or die("Unable to open $path");

while ($file = readdir($dir_handle))
{
   $filetype = filetype($file);
   if($file!="." && $file!=".."){
      echo "<tr class='dir'>";
      echo "<td><a href='dir/$file'>$file</a></td>";
      echo "<td>$filetype</td>";
      echo "<td></td>";
      echo "</tr>";
   }
}
closedir($dir_handle);
?>

 

I'm sure its something simple but, its really bugging me!

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

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.