Not a Member Yet,
Click here to Register

ID: 234
Viewed: 5700
Added: Jun 10, 2002
Snippet uploaded by: snippet
Written By: unknown
Demo: Sorry, no demo

User Rated at: 3 Stars3 Stars3 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Very handy to have around. you have a text file that is huge and want to append to it. but you don't want the new data to go clear to the bottom of the file. Well this script will let you do just the opposite. It will let you write to the file but put the new data at the begining and the old data at the end.



$file_name = "nieuws.txt";

#open and place the $fp point at the beginning of the file
$fp=fopen("$file_name", "r+");

#prevent the file from being messed up.
flock($fp, 2);

#read in the old data
$old_data = fread($fp, filesize($file_name));

# reset the file pointer to the start of the file so that the fwrite overwrites the original data

#concat the new data then the old data
fwrite($fp, "new data" . $old_data);

#release the lock, fclose can also do this

#close the file

No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.

Replying to a Comment...

Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!