Jump to content

[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>
	    $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
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.

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

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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