Axeia Posted April 29, 2009 Share Posted April 29, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/ Share on other sites More sharing options...
Maq Posted April 29, 2009 Share Posted April 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/#findComment-821927 Share on other sites More sharing options...
Axeia Posted April 29, 2009 Author Share Posted April 29, 2009 Does indeed seem to be case, mmmh bummer. Guess it's time to use exec() and some parsing then. Quote Link to comment https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/#findComment-821982 Share on other sites More sharing options...
Maq Posted April 29, 2009 Share Posted April 29, 2009 You could use chmod for proper permissions. Quote Link to comment https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/#findComment-822028 Share on other sites More sharing options...
Axeia Posted April 29, 2009 Author Share Posted April 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/#findComment-822041 Share on other sites More sharing options...
Maq Posted April 29, 2009 Share Posted April 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/#findComment-822106 Share on other sites More sharing options...
Axeia Posted April 29, 2009 Author Share Posted April 29, 2009 *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. Quote Link to comment https://forums.phpfreaks.com/topic/156142-solved-warning-filesize-stat-failed/#findComment-822191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.