in reply to Detect input type = file with CGI.pm

Where $param is a value returned by $cgi->param, this is how it's done internally:

if (ref($param) && defined(fileno($param)) { is file } else { isn't }

This should also work:

if ($cgi->uploadInfo($param)) { is file } else { isn't }

You only need to check if $cgi->content_type() eq 'multipart/form-data'.

Replies are listed 'Best First'.
Re^2: Detect input type = file with CGI.pm
by manta (Initiate) on Aug 18, 2010 at 13:07 UTC

    Hi,

    Thanks for your help. I did have to make one small change to the code you posted. For posterity, here's what I ended up with:

    if($query->uploadInfo($query->param($p))) { is file } else { isn't }
      Did you mistype something? That's the same thing I posted. Maybe it wasn't clear that $param is a value returned by param.