APD1993 Posted March 3, 2012 Share Posted March 3, 2012 Hi, I am writing several scripts and some are used to amend extra information to a text file. However, I added a hyperlink to the text file so that the user can go back to a page where they can add extra information. However, since I have done this every time I amend more text to the text file, the extra text appears below the hyperlink rather than above it, and I was wondering if there was a way around this. My amend code is as follows: <html> <head> <title>Amend File</title> <link rel="stylesheet" type="text/css" a href="rcm/stylesheet.css"> </head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="<p>Updated Information: " .$_POST['append']. "</p><br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" size="40" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> </body></html> And my text file is as follows: <h1>Accident Report</h1> <p>First Name: Andrew Last Name: Denman Age: 18 Complete Weeks Since Accident: 2<br> <a href="amendfile2.php">Amend to this file</a> Any help would be appreciated Link to comment https://forums.phpfreaks.com/topic/258174-how-can-i-amend-to-a-text-file-so-that-the-text-is-added-before-a-hyperlink/ Share on other sites More sharing options...
requinix Posted March 3, 2012 Share Posted March 3, 2012 You can't write to the middle of a file without overwriting whatever came after. You'd "have" to read in the whole file, make your change to the string in memory, then write it out. Link to comment https://forums.phpfreaks.com/topic/258174-how-can-i-amend-to-a-text-file-so-that-the-text-is-added-before-a-hyperlink/#findComment-1323448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.