Results 1 to 5 of 5
Thread: Editing a file
-
06-18-2005, 11:29 PM #1Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
Editing a file
Hi,
I got this page, where I got some textfiles which contain some settings. I want my users to be able to change these textfiles.
Like having something similar to an iframe, where the user can see the content of the textfile in the middle of my page, and a save button below after they have edited it. Is this possible with PHP? Thanks!
-
06-19-2005, 02:54 AM #2Web Hosting Master
- Join Date
- May 2004
- Location
- Toronto, Canada
- Posts
- 643
It is possible.
What you can do is have PHP open that textfile into a Multi line Text Field which will allow your users to edit it and save the changes.
-
06-19-2005, 03:40 AM #3WHT Addict
- Join Date
- Oct 2001
- Location
- Mountain Home Arkansas
- Posts
- 131
here is a couple links that would be a good starting point on how to do this....
http://us4.php.net/manual/en/function.fopen.php
http://us4.php.net/manual/en/function.fread.php
http://us4.php.net/manual/en/function.fread.phprocket science is more fun when you accually have rockets!
-
06-19-2005, 03:41 AM #4Web Hosting Master
- Join Date
- Jul 2003
- Posts
- 662
OF course it's possible, there are some things to consider:
1. The files need to be writeable by the webserver (user nobody/httpd/apache) if the server doesn't allow suexec.
2. You'll load the file in a "textarea" not a "multi line text field" as dbgohan said.
3. Once it's edited the best way to avoid overwriting/locking would be to erase the entire file and write it again.
you'll use the following PHP functions:
fopen() to open the file
fread() to read the contents of the file
fputs() to write the user's input back into the file
fclose() to close an open file pointer
You can even get fancy and add some functions like converting special characters to avoid sql injection problems or parsing specific strings (like vBulletin and other forum scripts do to allow "customized code" - vbcode in vBulletin).
-
06-19-2005, 04:41 AM #5Aspiring Evangelist
- Join Date
- Feb 2005
- Location
- Norway
- Posts
- 391
umm Okey.. thanks for replies. I'll continue trying then :]