Truncate file in the middle?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MarcoB
Forum Newbie
Posts: 1
Joined: Wed May 28, 2008 3:35 pm

Truncate file in the middle?

Post by MarcoB »

Is there a way to truncate a file in the middle of it? For example, if I have a 4096-byte file, and the file pointer is at 80 bytes, I just want to delete the next 1024 bytes from that pointer and nothing else. Is there a way to truncate a file in the middle like that, operating only on the file itself?

To start, ftruncate() only deletes at the end of the file. I could certainly store the preceding and following sections of the file in vars and just put those together -- that's very easy -- but since I'm working on memory constraints (the files I'm working on are at least 100MB,) I wanted to know if there's a better/simpler way...?
Post Reply