Jump to content

Archived

This topic is now archived and is closed to further replies.

Axeia

[SOLVED] Warning: filesize(): stat failed

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Does indeed seem to be case, mmmh bummer. Guess it's time to use exec() and some parsing then.

Share this post


Link to post
Share on other sites

You could use chmod for proper permissions.

Share this post


Link to post
Share on other sites

Script is intended for a sort of 'filebrowser', not really an option as doing a chmod -R just so that PHP can get the filesize is silly.

Share this post


Link to post
Share on other sites

Script is intended for a sort of 'filebrowser', not really an option as doing a chmod -R just so that PHP can get the filesize is silly.

 

True, and it's just a warning which, should be suppressed on production servers anyway.

Share this post


Link to post
Share on other sites

*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.

Share this post


Link to post
Share on other sites

×

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.