PHP Fopen() r+
|
Original Message
|
Name: codyhtml
Date: March 19, 2005 at 15:05:41 Pacific
Subject: PHP Fopen() r+OS: DebianCPU/Ram: ??? |
Comment: Hello I'm writing a simple guest book type script that it recievies info from a form and then writes it to a file then a page will read the file it writes it to but when i use r+ or anything it always adds it to the end of the file it isent a huge deal but i would kind of like the newer posts to be at the top
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Michael J (by mjdamato)
Date: March 19, 2005 at 16:54:26 Pacific
Subject: PHP Fopen() r+ |
Reply: (edit)You will have to code around it. Try this: 1. (assuming the file is called guest.txt) Rename guest.txt to guest-temp.txt. 2. Create a new guest.txt and write the new entry to it. 3. Read guest-temp.txt and then write it back out to guest.txt. You might have to do this in chunks. 4. When done, delete guest-temp.txt Michael J
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: jam14online
Date: March 20, 2005 at 01:04:27 Pacific
Subject: PHP Fopen() r+ |
Reply: (edit)I had the same problem a while ago in this post. I never got the "r+" method to work. However, if you visit my web site then you can download my simple guest book script which has a good feature set at the moment and could easily be expanded to do anything else you want. MiniApache - a simple, fast and free web server
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: anonproxy
Date: March 20, 2005 at 21:30:09 Pacific
Subject: PHP Fopen() r+ |
Reply: (edit)I haven't experienced your problem, but here is one thing to try (per Micheal's suggestion). I shamelessly borrowed this from somewhere: /*No r+ required*/ $file = "test.txt"; $contents = file_get_contents($file); $contents = "Add this text to the file".$contents; $fp = fopen($file,"w"); fwrite($fp,$contents); fclose($fp); /*end example*/
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: