Martin DiViaio on 24 Nov 2003 22:52:02 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] CGI.pm file upload headers??


[...]

On the 24th day of November in the year 2003 you wrote:

> Date: Mon, 24 Nov 2003 19:07:35 -0800 (PST)
> From: Marc Zucchelli <marcz908@yahoo.com>
> To: plug@lists.phillylinux.org
> X-Spam-Status: No, hits=0.9 required=5.0
> 	tests=FROM_ENDS_IN_NUMS,IN_REP_TO,SPAM_PHRASE_00_01
> 	version=2.44
> Subject: [PLUG] CGI.pm file upload headers??
> 
> When uploading a file from a webform and retrieving it
> with CGI.pm, is there a way to grab the headers?  For
> example:
> $file = $cgiinput->param('file');
> where $file is a file handle for the data, and it
> contains the actual name of the file as a scalar, but
> what if I want to grab say the mime type header?
> 
> Content-type: image/jpeg
> 
> I know that CGI.pm parses this information, but I dont
> know what the actual official way of retrieving it is
> if there is one, any one have any ideas?


CGI.pm has an enormous amount of documentation built into the module in 
POD format. For instance:

       When a file is uploaded the browser usually sends along some informa-
       tion along with it in the format of headers.  The information usually
       includes the MIME content type.  Future browsers may send other infor-
       mation as well (such as modification date and size). To retrieve this
       information, call uploadInfo().  It returns a reference to an associa-
       tive array containing all the document headers.
                                                                                
              $filename = $query->param('uploaded_file');
              $type = $query->uploadInfo($filename)->{'Content-Type'};
              unless ($type eq 'text/html') {
                 die "HTML FILES ONLY!";
              }

Do a 'perldoc CGI' for more.


___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug