| Site Map | WizTools.org | jCraze Blog |
![]() |
Edit Your Site Online (using PHP)During the infancy of indiWiz.com, the first page of the site 'index.php' was almost a static one. The only PHP thing in it was a basic counter. There was, and is, the editorial 'From Subhash...' which was frequently updated. So what I did was upload (through FTP) this whole file 'index.php' to change the editorial content. Later I shifted the editorial content to a separate file 'temp.html' and included it dynamically in 'index.php' using the 'include' statement. But even this procedure required me to upload the file 'temp.html' using FTP. To overcome this ineffeciency, I wrote a program to edit the file 'temp.html' online. The working of this program is explained below. This program at first fetches the page to be edited and prints the content of this page on a text field. You have to type the new text or edit the original one in this text field. Whenever you press the 'submit' button of the form, the changed text is inserted to the file. Code I: To Print The Content in a Text Field<form action="processscript.php" method="post"> This PHP code uses three functions:
Note: 'file.ext' should be writable. Give 'chmod 666' command to this file if you are using a UNIX/Linux server. Code II: To Insert the Changed Text<? I pass the $_POST['content'] variable through the stripslashes() because I noticed that slashes are automatically added to some special characters (like: ' ;) in the content passed through GET/POST in certain configuration. The other statements must be familiar to C programmers: we open the file in write mode (the 'w' parameter in the fopen() function). Then we write the new content $content to the file using fputs(). At last we close the file. As simple as that! |
[Quick Stats: Number of main threads: 2, Number of sub-threads: 1]
Sign Guestbook
|
Who is Subhash?
The contents of this site are copyright© 2000-2008, indiWiz.com. All Rights Reserved.