Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Getting File Type using Regular Expressions

by kiat (Vicar)
on Apr 21, 2004 at 15:04 UTC ( #347024=note: print w/replies, xml ) Need Help??

in reply to Getting File Type using Regular Expressions

May be you could try this (You said 'uploading' so I'm assuming it may be web-based):

use CGI; my $q = new CGI; my $file = $q->param('myfile') my $type = $q->uploadInfo($file)->{'Content-Type'}; print "$type\n";

Replies are listed 'Best First'.
Re: Re: Getting File Type using Regular Expressions
by bkiahg (Pilgrim) on Apr 21, 2004 at 17:13 UTC
    Yes it is a CGI ap. What is the difference between $q->uploadInfo($file)->{'Content-Type'}; and using File::Type or File::MMagic? Do they check the same thing or what criteria do the base their assumptions on?

      The code:

      $type = $query->uploadInfo($filename)->{'Content-Type'};
      returns the Content-Type header the browser added to the upload. Basically, it's what the browser (or the user's computer) thinks this file is. It's not fool-proof however, and browsers are not required to include it.

      See the CGI documentation for more information.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://347024]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2020-08-13 20:51 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (75 votes). Check out past polls.