10-21-2011, 03:38 PM
Hello,
I am getting a error when I use a post variable to edit a file on the server.
What I want is to enter the name of the file and then edit it.
Here is my code:
First file "editor.php"
Second file "editpage-2.php"
The problem is when I hit the save button, it shows this error:
Notice: Undefined index: page in C:\xampp\..\editpage-2.php on line 3
Warning: fopen() [function.fopen]: Filename cannot be empty in C:\xampp...\editpage-2.php on line 11
Error opening file in write mode!
Is there any thing that I missed?
Thank you all,
Inventor
I am getting a error when I use a post variable to edit a file on the server.
What I want is to enter the name of the file and then edit it.
Here is my code:
First file "editor.php"
PHP Code:
<form action="editpage-2.php" method="post" />
<input type="text" name="page" />
<input type="submit" value="Submit" />
</form>
Second file "editpage-2.php"
PHP Code:
<?php
$firstfile = $_POST['page'];
echo $firstfile; // the file is shown, and is there
$fn = $firstfile;
if (isset($_POST['content']))
{
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
<textarea rows="10" cols="100" name="content"><?php readfile($fn); ?></textarea><br />
<input type="submit" value="Save" VALUE="Refresh">
</form>
The problem is when I hit the save button, it shows this error:
Notice: Undefined index: page in C:\xampp\..\editpage-2.php on line 3
Warning: fopen() [function.fopen]: Filename cannot be empty in C:\xampp...\editpage-2.php on line 11
Error opening file in write mode!
Is there any thing that I missed?
Thank you all,
Inventor