php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2829 writing in a file with fwrite()
Submitted: 1999-11-25 16:04 UTC Modified: 2001-02-10 15:24 UTC
From: arthur dot angelier at iq3 dot nl Assigned:
Status: Closed Package: Other
PHP Version: 3.0.11 OS: Windows NT
Private report: No CVE-ID: None
 [1999-11-25 16:04 UTC] arthur dot angelier at iq3 dot nl
First of all, i like PHP verry much.
It's an easy to learn and very usefull language.
Still i have a little problem.

I open a file with fopen() and i read in it with fread().
Then i set the filepointer with fseek() and i verify that
action with ftell().
So far all goes well.
But when i write to the file with fwrite(), i find that
the bytes i wrote are always appended to the file and not
written somewhere in the middle, at the position that i
placed the filepointer on.

So if i have a file with, let's say, 20 bytes (0 - 19),
and i position the filepointer at byte 10, then i should be
able to write in the middle of the file, right?
This doesn't happen.

And how can i truncate an opened file to a specific length?
I want to truncate this file with 20 bytes to a length of
14 bytes. How can i do this?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-26 15:55 UTC] hholzgra@php.net

for #2 there is a ftruncate() function available in php4

for #1: if this still doesn't work with current php3 (or php)
        i'd like to see some sample code 
 [2001-02-10 15:24 UTC] jimw@php.net
no feedback, closing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC