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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fbernardi at bbros dot it
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 03:01:32 2025 UTC