Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filesize error

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
I have this code which produces this error:
Code:
Warning: filesize(): Stat failed for MJB3K-B4t3s_songs.html (errno=2 - No such file or directory) in /home2/webrevol/public_html/readDir.php on line 5
MJB3K-B4t3s_songs.html: 0 KB
Here is the code i'm using:
Code:
if ($handle = opendir('messaging_files/')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
			echo $file . ': ' . round(filesize($file)/1024) . ' KB';
           //echo "$file - " . filesize($file) . "\n";
       }
   }
   closedir($handle);
}
Any ideas??


Regards,

Martin

Computing Help And Info:
 
It's probably the simple thing I've been overlooking until now. filesize() requires a filename string. Since you're getting the filenames via readdir() on a subdirectory of your script's current directory, that subdirectory needs to be included in the filename.

Try:

Code:
<?php
$dirname = 'messaging_files';
if ($handle = opendir($dirname))
{
	while (false !== ($file = readdir($handle)))
	{
		if ($file != "." && $file != "..")
		{
			echo $file . ': ' . round(filesize($dirname . '/' . $file)/1024) . ' KB';
		}
	}
	closedir($handle);
}
?>



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top