Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:

I've been trying to figure out how file uploads work from Mac browsers.

The form field seems to contain, not a path but just the final file name, when I code up a form with an INPUT TYPE="file" field. It's not in any of the ENV{} variables I can see either.

Obviously, CGI.pm handles these things just fine, but how?

By which I mean, please do tell me to read the manual, but where?

I've tried looking at the source of CGI.pm but I couldn't seem to find what I was looking for.

Clues, anyone?
--

($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

Replies are listed 'Best First'.
Re: Macs and File Uploads
by rob_au (Abbot) on Jun 18, 2002 at 07:32 UTC
    Okay, while I'm not exactly sure where you are having problems, I think I can help you out ... When submitting a file upload via HTTP, a multi-part request must be made by the client - For example ...

    <form action="/cgi-bin/..." enctype="multipart/form-data" method="post +"> ... </form>

    This type of request submits the form field information and the 7-bit encoded file via POST, separated by a boundary separator that delimits these two sections. The CGI parameter from the file field will contain the name of the file, while the file itself must be parsed from the request separately - A lot of this magic is hidden in the init and read_multipart subroutines of CGI.pm, based upon RFC1867.

    It should also be noted that the value of the file field form parameter is platform dependent and as such, it cannot be depended upon to return both directory and filename of the uploaded file.

    As such, if you are using your own CGI parameter parser, it is more than likely that you are simply not extracting this information from the submitted POST - This is another reason why it is better to use CGI.pm rather than a hand-rolled parser based upon cgi-lib.pm (see use CGI or die;).

     

      Thank you for that. I get it now.

      I think the thing I was also missing is that it's not the CGI script or module's business where on the disk the file is, that's the browser's business.

      The fact that different platforms display different info in the field of the form is neither here nor there.
      --

      ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;