php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27575 ftell reports the size of appended bytes instead of the file pointer position
Submitted: 2004-03-11 14:33 UTC Modified: 2004-03-11 15:33 UTC
From: fbernardi at bbros dot it Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.4 OS: Red Hat Linux
Private report: No CVE-ID: None
 [2004-03-11 14:33 UTC] fbernardi at bbros dot it
Description:
------------
ftell() reports the size of bytes added to a file instead of the position of the file pointer in the file.
I guess this behavior is reproduceable only on appending data to a file, since on new files the file pointer position is at the same place of the number of bytes added.

Reproduce code:
---------------
<?php
# Adding something to the test-file to see the behavior
$fp = fopen("test", w);
fwrite($fp, "Ciao");
fflush($fp);
fclose($fp);
# test-file saved and closed

# Opening a file with non-zero size (just added some bytes)
$fp = fopen("test", a);
fwrite($fp, "Ciao");
fflush($fp);
$s = filesize("test");
$t = ftell($fp);
print("The pointer should be at the position $s, but ftell reports $t");
fclose($fp);
?>


Expected result:
----------------
The pointer should be at the position 8, but ftell reports 8

Actual result:
--------------
The pointer should be at the position 8, but ftell reports 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-11 15:33 UTC] wez@php.net
Duplicate of Bug #24071.
You cannot rely on ftell() or fseek() when working with an append-only stream.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 02 14:01:32 2024 UTC