After a long break in PHP side Im posting this script to edit any text files in the server. There are also lots of free online text editors. But there is a need to have some own text editor in your server. Im also using this script to edit text files in my server.
Php script to edit text files
As I've already said this is simple form of the script so it is programmed to edit a single predefined text file(test.txt). This program cannot navigate through your server so place the text files in the folder where the php file is located.
Installation
Create a separate folder where all txt files are kept
Copy the below code and create index.php of that folder
Change the $text name with your text file name with extension chmodded to 777
As the program does not able to create txt in its own, you should create on your own.
Editing for your preference
To edit multiple files you may use Get function in text variable. $text = $_GET['n'];
When you are using multiple files call yourdomain.com/folder/index.php?n="name" or use a form like this
As I've already said you need to create files on your own and remember them. You can also create a dropdown list with all files. Don't forget to chmod files to 777
$text = "test.txt" ;
if (isset( $_POST [ 'content' ]))
{
$content = stripslashes ( $_POST [ 'content']);
$fp = fopen ( $text , "w" ) or die ( "Error opening file in write mode!" );
fputs ( $fp , $content );
fclose ( $fp ) or die ( "Error closing file!" );
}
?>
If you are able to edit the code and improve it please comment below and i will update it.
Comments
Post a Comment
Don't fell shy to post your comments. You are welcome always.