Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP edit file on server?
#1
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"
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
Reply


Messages In This Thread
PHP edit file on server? - by Inventor - 10-21-2011, 03:38 PM
RE: PHP edit file on server? - by Gaijin - 10-21-2011, 04:25 PM
RE: PHP edit file on server? - by Inventor - 10-21-2011, 04:57 PM
RE: PHP edit file on server? - by Gaijin - 10-22-2011, 04:24 AM
RE: PHP edit file on server? - by Inventor - 10-22-2011, 07:19 AM
RE: PHP edit file on server? - by saikiran - 08-08-2012, 04:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 773 07-27-2020, 11:26 PM
Last Post: tk-hassan
  Use PHP in a text file? Blic 4 1,231 10-25-2011, 08:12 PM
Last Post: Project Evolution
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,264 10-10-2011, 01:00 PM
Last Post: Greyersting
  help : PHP : Executing .jar file killer_03 0 1,032 03-12-2011, 11:09 PM
Last Post: killer_03
  Common PHP and SQL [File-Sharing Site] Project Evolution 3 1,676 12-12-2010, 02:47 AM
Last Post: Bursihido

Forum Jump:


Users browsing this thread: 1 Guest(s)