Updating a text file
Posted: Thu Feb 18, 2010 1:59 pm
This code worked on another server to update a text file, but is not working now. PHP is definitely running on the server, and the text files are where they need to be. Here's the code I inherited (I don't know PHP - just modifying an already-existing site)
<?
if($_POST['Submit']){
$open = fopen("time1.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("time1.txt");
foreach($file as $text) {
echo $text."<br />";
}
echo "<p><a href=\"./fundraising.htm\">click here to view the live updated webpage</a></p>";
echo "<p><a href=\"./fundraising-edit.php\">click here to view the admin menu</a></p>";
}else{
$file = file("time1.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>
<?
if($_POST['Submit']){
$open = fopen("time1.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("time1.txt");
foreach($file as $text) {
echo $text."<br />";
}
echo "<p><a href=\"./fundraising.htm\">click here to view the live updated webpage</a></p>";
echo "<p><a href=\"./fundraising-edit.php\">click here to view the admin menu</a></p>";
}else{
$file = file("time1.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>