Forum Moderators: coopster

Message Too Old, No Replies

Editing Text File with a PHP Form

         

cobra

8:04 pm on Dec 17, 2003 (gmt 0)

10+ Year Member



Hey guys,

First time posting here, but hope you can help. I am trying to do something with PHP that i am sure is pretty easy. But not sure myself how to do it.

I have a file that i want to pull into a simple HTML Form text field. From that field the person can just add in content or remove content.. Click "Update" .. And it will write the new content out.. Overwriting the old file if need be.

Would anyone be able to give me some help with it? I have tried and tried and all i am getting is errors.

Much appreciated guys.

Cob.

dmorison

9:01 pm on Dec 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi cobra

You are correct - it is straight forward to do what you want, with one exception:

File Permissions

Assuming that you are on *nix/Apache configuration, when PHP attempts to access a file on your server, it is doing so as if it were the user that Apache is running as.

On default installs, this is usually the user "apache", so the first thing you have to have to do is make sure that the user "apache" has read/write permissions to the file you want to use.

To get the contents of the file when building your form, use fopen() [uk.php.net] and then fread() [uk.php.net].

When the user submits the form, you would again use fopen(), to open the file in write mode, and use fwrite() [uk.php.net] to write the new contents to the file.

The above links go the PHP website where you will find full documentation for those functions, including examples to do what you require.