I have a web gallery application which, not unreasonably, allows photo uploading. The code that handles uploads, stripped of redundant parts, is essentially this:

$q = CGI->new(); %form = $q->Vars; ... $file = $form{photo}; $fh = upload('photo') || error ($q,"Cannot upload file $file"); $info = uploadInfo($q->param('photo')) || error ($q,"Could not get + information about $file!"); unless ($errors) { $type = $info->{'Content-Type'}; unless ($type =~ m,^image/(jpeg|gif|png)$,) { error ($q, "File type '$type' is not permitted"); } ...

When I test this code from the submission form, all the form fields appear correct, upload() succeeds, but uploadInfo() fails. In the absence of the check for errors, this causes $info->{'Content-Type'} to throw an 'undefined value as HASH reference' error. $q->cgi_error sheds no light on the failure.

Can anyone suggest why uploadInfo() is failing, even though upload() has succeeded?


In reply to CGI.pm: upload() succeeds, uploadInfo() fails by Llew_Llaw_Gyffes

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.