Jump to content

Writing to the middle of a file


mrkfox

Recommended Posts

What is the file being used for?

 

Is the file used for data-storage (read/write by a computer)? or is it like a document where it's a bunch of text intended to be read by a human (and not a computer).

 

If it's for data-storage, use a Database or XML (I guess you could use INI - ewwwwww).

A Database would probably be the easiest.

You should be able to do this with fseek.  Fseek moves the file pointer to a certain location.  You can get the middle of the file's location using filesize along with the above function... and divide it by 2.

 

Use fwrite for writing to the file.  And use fopen to open the file to begin with.

 

example

$theFile = fopen("myFile.txt", 'w');
fseek($theFile, (filesize($theFile)/2));
fwrite($theFile, "The middle of the file");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.