Forums
This topic is locked
editing and saving text file
Posted 03 Sep 2004 18:30:19
1
has voted
03 Sep 2004 18:30:19 Dave Desormeaux posted:
I've created a page in an admin section that will allow users to edit and save a text file using PHP. I've picked up code from a previous posting and it works except for one detail: each time I submit my form, an extra space is added at the top of the text file. How can I ensure that this doesn't happen? I've checked the txt file to make sure there are no spaces already there (the text file I am using contains meta information - description and keywords).Here is the code for the admin page:
<?php
$filename="metatags.txt";
$fd=fopen($filename,"r"
$textFileContents=fread($fd,filesize($filename));
fclose($fd);
if ($frmSub) {
$fd=fopen("metatags.txt","w"
fwrite($fd, $newdata);
fclose($fd);
}
?>
<html>
<head>
<title>Edit Metatags</title>
</head>
<body>
<form action="<? echo $PHP_SELF; ?>" >
<textarea name="newdata" rows="10" cols="40">
<?
echo stripslashes($newdata);
?>
</textarea>
<input type="submit" name="frmSub" value="submit">
</form>
</body>
</html>
Thanks!
Dave