mattheww Posted January 14, 2010 Share Posted January 14, 2010 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 More sharing options...
lemmin Posted January 14, 2010 Share Posted January 14, 2010 You need to specify the directory name where that file is. Your $file variable only contains the "basename" of that file and it doesn't exist in your script's root directory. Try it like this: $filetype = filetype($path.$file); Link to comment https://forums.phpfreaks.com/topic/188500-php-directory-listing/#findComment-995147 Share on other sites More sharing options...
mattheww Posted January 14, 2010 Author Share Posted January 14, 2010 ahh, that makes sense, Thanks lemmin! Link to comment https://forums.phpfreaks.com/topic/188500-php-directory-listing/#findComment-995155 Share on other sites More sharing options...
mattheww Posted January 14, 2010 Author Share Posted January 14, 2010 That worked previously, which is good however i need the mime file thingo so i did $filetype = mime_content_type($path.$file); and it hasn't worked saying a similar thing! Link to comment https://forums.phpfreaks.com/topic/188500-php-directory-listing/#findComment-995166 Share on other sites More sharing options...
lemmin Posted January 15, 2010 Share Posted January 15, 2010 What is that error? Have you tried finfo_file()? http://us2.php.net/manual/en/function.finfo-file.php Link to comment https://forums.phpfreaks.com/topic/188500-php-directory-listing/#findComment-995821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.