On 20 Jun 2008 at 11:43, Mimi Cafe wrote:
> I need to write a cgi program to enable our users to upload files using the
> web browser, but I am not sure how to figure out the type of file the user
> wants to upload (e.g text or binary file). Can CGI.pm accomplish this
> automatically?
> 
> Any suggestions welcome.


Have a look at this from the highly secretive CGI documentation :-)

When a file is uploaded the browser usually sends along some 
information along with it in the format of headers. The information 
usually includes the MIME content type. Future browsers may send 
other information as well (such as modification date and size). To 
retrieve this information, call uploadInfo(). It returns a reference 
to an associative array containing all the document headers.

       $filename = param('uploaded_file');
       $type = uploadInfo($filename)->{'Content-Type'};
       unless ($type eq 'text/html') {
          die "HTML FILES ONLY!";
       }


Dp.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to