Results 1 to 5 of 5

Thread: Editing a file

  1. #1
    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!

  2. #2
    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.

  3. #3
    Join Date
    Oct 2001
    Location
    Mountain Home Arkansas
    Posts
    131
    rocket science is more fun when you accually have rockets!

  4. #4
    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).
    Fabio A. Calderon
    C.E.O.
    SEATi

  5. #5
    Join Date
    Feb 2005
    Location
    Norway
    Posts
    391
    umm Okey.. thanks for replies. I'll continue trying then :]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •