Edit report at http://bugs.php.net/bug.php?id=53064&edit=1
ID: 53064 Updated by: cataphr...@php.net Reported by: mraaijmakers at gmail dot com Summary: filsize return 0 after is_file Status: Open Type: Bug Package: Filesystem function related Operating System: Linux Ubuntu PHP Version: 5.2.14 Block user comment: N New Comment: That's just stale stat cache. This will work: <?php $filename = dirname(__FILE__) . '/test.txt'; $fh = fopen($filename, 'w+'); $isFile = is_file($filename); fwrite($fh, 'some data goes here!'); fclose($fh); clearstatcache(false, $filename); var_dump($isFile, file_get_contents($filename), filesize($filename)); I'm not closing because maybe there's a way to invalidate the cache for that file with a negligent performance penalty. Previous Comments: ------------------------------------------------------------------------ [2010-10-14 08:38:22] mraaijmakers at gmail dot com Description: ------------ When using is_file() on a file which is open via fopen(), the filesize() function returns 0, even after fclose() is called; see test script. Test script: --------------- $filename = dirname(__FILE__) . '/test.txt'; $fh = fopen($filename, 'w+'); $isFile = is_file($filename); fwrite($fh, 'some data goes here!'); fclose($fh); var_dump($isFile, file_get_contents($filename), filesize($filename)); Expected result: ---------------- boolean true string 'some data goes here!' (length=20) int 20 Actual result: -------------- boolean true string 'some data goes here!' (length=20) int 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53064&edit=1