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:
  1. Determine which file is going to be edited, based on the command-line parameter.
  2. 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.
  3. Fix the content so that it works with the TEXTAREA box.
  4. 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/&/&amp;/g; s/</&lt;/g; s/>/&gt;/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.

In reply to Re: Creating new HTML files and accessing them later. by tadman
in thread Creating new HTML files and accessing them later. by bladx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.