Ok, this is a meditation because some other people might not have thought of this use of a CGI script written in Perl, and because it is, IMHO, quite secure.

Imagine yourself having a website, and even imagine yourself having a dynamic one, database-based, with Perl as the language of choice (of course, there is no need to disguise Perl in PHP :-)

Well, imagine also that you don't have lots of time to update your website, so that you have implemented a site management/update feature in your website Perl scripts.

Now, meditate... You would also like to be able to upload files (e.g. image files for your articles) to your site. You could use the CGI.pm module, but you think that the file upload function there is quite slow and you prefer exploring your brain to find a cooler way to do it.

Well, here is my meditation (which has actually been implemented right now!):

1)Your updating CGI script has a file input textfield, so that you can select a file of your hard disk to upload.

2) When you submit the script, the CGI attempts a SOCK_STREAM connection to your computer, on a port that only YOU knows and asks for the file if it finds somebody listenning. The CGI knows your IP, provided that your are not behind a silly firewall, with $ENV{REMOTE_ADDR}.

3) This "somebody listenning" is nothing else than a little file server, written in Perl of course (10 lines) that you launched right before you accessed the CGI script in your browser (or at least, before you submitted the form containing the file to upload).

4) The connection is established, and the file transferred, fast. When the local file server has done its job, just shut it down and keep meditating. There are so many things you can still achieve in the Perl mankind.

5) Amen

In reply to Cool CGI File Uploading by gaggio

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.