solarisuser Posted April 19, 2006 Share Posted April 19, 2006 Hello, I use fputs to write to a file, but I can only find documentation stating this function writes to the bottom of the file. I'd like to add text to the beginning of a file. Anyone out there have some code to do such a thing?Thanks Quote Link to comment Share on other sites More sharing options...
ober Posted April 19, 2006 Share Posted April 19, 2006 You will have to read the file into a string, write your new output to the file and then write your old string back to the end of the file. There's no function to do this otherwise. Quote Link to comment Share on other sites More sharing options...
litebearer Posted April 20, 2006 Share Posted April 20, 2006 try this[code]function write_beg($filename, $data){ //Imports old data $handle = f open($filename, "r"); $old_content = f read($handle, filesize ($filename)); f close($handle); //Sets up new data $final_content = $data.$old_content; //Writes new data $handle2 = f open($filename, "w"); $finalwrite = f write($handle2, $final_content); f close($handle2);} [/code]everywhere there is a f with a space after it, remove the space.Lite... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.