Jump to content

[SOLVED] Warning: filesize(): stat failed


Axeia

Recommended Posts

Getting an warning like this one:

Warning: filesize(): stat failed for /home/??????/Shared/?????/Running/File.mp4 in /srv/www/htdocs/???????/index.php on line 169 

And this bit is to blame for it.

            foreach( $files as $file )
    {
	if( pathinfo( __Directory__.$file, PATHINFO_FILENAME ) != '' )
	{
	    echo "\t\t\t"."<tr class='o$odd'>
	      <td>".pathinfo( __Directory__.$file, PATHINFO_FILENAME )."</td>
	      <td>".pathinfo( __Directory__.$file, PATHINFO_EXTENSION )."</td>
	      <td>".filesize( __Directory__.$file )."</td>
	    </tr>";
	    $odd =! $odd;
        }
            }

Quite puzzling as getting the file name/extension is no problem, but for some reason the filesize is giving me problems.

If it's of any help, the server is a linux box (openSUSE 11.1) and the disk is using the ext3 filesystem.

 

Could work around it with exec() I guess, but I'm trying to keep this script distributable

Link to comment
https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/
Share on other sites

On php.net, one of the posts mentions:

 

Be aware to use this function on files/dirs which are NOT writeable: you will get a warning like:

 

Warning: filesize() [function.filesize]: stat failed for /var/www/xxx/yyy.php in /var/www/xxx/yyy.php on line 123

 

Which sounds like your problem.

*nods* that's up to the settings of the server though. Besides the warning it didn't give any results either making it useless.

 

If anyone ever stumbles upon this topic, I'm using the following code now:

exec( ( 'du -b "'.__Directory__.escapeshellcmd( $curFolder ).'/"*'), $filenames );
foreach( $filenames as $key => $val )
{
    $size = substr( $val, 0, strpos( $val, '/' ) );
    $filename = substr( $val, strpos( $val, __Directory__ ) + strlen(__Directory__) );
    $filenames[$filename] = $size;
    unset( $filenames[$key] );
}
print_r( $filenames );

Which creates an associative array where the key is the filename and the value the filesize in bytes. If I write a windows version I'll post it in this thread.

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.