From:             perrog at gmail dot com
Operating system: Mac OS X 10.4
PHP version:      5.2.1RC3
PHP Bug Type:     Filesystem function related
Bug description:  fopen() for appending does not move position until first I/O

Description:
------------
Opening a file for appending does not move the file pointer to 
the end of file before the first I/O operation is performed.

That makes ftell() return zero directly after the fopen() 
call.

The workaround, if you need to call ftell() immediately after 
the fopen(), is to use a no-operation I/O call fseek() that 
don't do anything. Thus, the file pointer is updated and 
returns correct position information.

Reproduce code:
---------------
// create or open a file, and write some stuff to it.
$filename = "/path/to/file.txt";
$fp = fopen($filename, "a+");
fwrite($fp, "Sample text");
fclose($fp);

// re-open it and check what ftell() returns
$fp = fopen($filename, "a+");
echo " pre-fseek: " . ftell($fp) . "\n"; // ftell returns 0
fseek($fp, 0, SEEK_END);
echo "post-fseek: " . ftell($fp) . "\n"; // ftell now ok


Expected result:
----------------
The snippet should print the file size of the file:

 pre-fseek: 11
post-fseek: 11

Actual result:
--------------
The snippet should print the correct file size only after the 
first I/O operation:

 pre-fseek: 0
post-fseek: 11

-- 
Edit bug report at http://bugs.php.net/?id=40183&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=40183&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=40183&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=40183&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40183&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=40183&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40183&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40183&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40183&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40183&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40183&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=40183&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=40183&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40183&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40183&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40183&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40183&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40183&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40183&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40183&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40183&r=mysqlcfg

Reply via email to