The Quick-and-Dirty way to do this is to write a CGI script
that can edit files, even if they don't exist. So, what
you have is a big <TEXTAREA> tag with your file inside
it, and you edit, and you submit, not unlike Perl Monks.
With
CGI.pm, this is really quite easy, so I won't take
all the fun out of it by posting the little program here.
The procedure is:
- Determine which file is going to be edited, based
on the command-line parameter.
- Open the appropriate file, if it exists, and read in
the contents. Don't die if you can't, just ignore it,
as they are starting on a "new" file.
- Fix the content so that it works with the TEXTAREA box.
- Return a FORM which will SUBMIT to the proper "save"
script.
The "save" script just takes whatever it is given and dumps
it into the appropriate file, so make sure to give them a
"Cancel" button which does nothing dangerous.
You will also likely need a "directory" script which shows
you all the files that can be edited, where the links point
to the edit script keyed with that file as the parameter.
To edit a "new" file, put in an INPUT box where they can
type in the name.
To make everything jive with the TEXTAREA tag, you have to
make sure that it's all HTML-savvy, which means doing
something to the "dangerous" stuff on the way in:
s/&/&/g; s/</</g; s/>/>/g;
Then you can pile it back in your file when you're finished.
Provided the script has access to the files it is trying
to edit and write to, you're golden.
Warning:
Be aware that you must secure this script properly, or you
are opening yourself up to a world of hurt. Make sure
that you use something like 'htpasswd' at the very least,
and SSL (i.e. Apache-SSL) if you are able to do that.
I've done this before, and it's an easy way for users to
"upload" new pages by doing something as simple as cut-and-paste
from their HTML editor.