frinky, the limitation that you have run into is one of the many reasons why people recommend that you use CGI.pm or one of its (few) competitors on the CPAN. Your code cannot handle file uploads and is unlikely to be able to do so at any point in the future. This is because the encoding for 'multipart/form-data' is much different from the standard encoding that you are used to. Lets look at a standard upload form.

<form action="/cgi-bin/display.cgi" method="post" enctype="multipart/f +orm-data"> <input type="file" name="file" /><br /> <input type="hidden" name="hiddenData" value="nothing to see h +ere, folks" /><br /> <input type="checkbox" name="someCheckbox" value="someValue" check +ed="checked" />Checkbox<br /> <input type="submit"><br /> </form>

Let's say that I use that form to upload a small file named 'temp.pl'. The entity-body (the part after the headers) that is sent to the browser might resemble the following:

-----------------------------7d03ca41c0 Content-Disposition: form-data; name="file"; filename="C:\WINDOWS\Desk +top\temp.pl" Content-Type: text/plain #!C:/perl/bin/perl.exe -w use strict; $SIG{INT} = 'IGNORE'; my $count=0; while (){ print $count++; } -----------------------------7d03ca41c0 Content-Disposition: form-data; name="hiddenData" nothing to see here, folks -----------------------------7d03ca41c0 Content-Disposition: form-data; name="someCheckbox" someValue -----------------------------7d03ca41c0--

Not only is that rather difficult to parse, but different browsers often have subtly different formats for multipart/form-data. Debugging those issues can be a nightmare. That is one of the many reasons people suggest that you use a standard module instead of trying to roll your own.

Since CGI.pm is part of the standard distribution, you should have no problem using it. Check out Lesson 2 of my CGI course for more information about this topic.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Re: Can I do a file upload without using any modules? by Ovid
in thread Can I do a file upload without using any modules? by frinky

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.