Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Thoughts on file upload...

by mojobozo (Monk)
on Nov 20, 2002 at 16:01 UTC ( #214507=note: print w/ replies, xml ) Need Help??


in reply to Re: Thoughts on file upload...
in thread Thoughts on file upload...

A snippet:

my %file_ok = qw{ .gif 1 .jpg 1 .htm 1 .html 1 .txt 1 .doc 1 .pdf 1 }; and then.... ($base,$path,$type) = fileparse($file,'\..*'); and finally... $type =~ tr/A-Z/a-z/; if (!$file_ok{$type}) { print "The type of file you tried to upload ($type) is not sup +ported."; return; }
how's that?
UPDATE: Added the line to make the extension lowercase as some losers in my industry love CAP LOCK.
_____________________________________________________
mojobozo
word (wrd)
interj. Slang. Used to express approval or an affirmative response to
something. Sometimes used with up. Source


Comment on Re: Re: Thoughts on file upload...
Download Code
Re: Re: Re: Thoughts on file upload...
by valdez (Monsignor) on Nov 20, 2002 at 16:25 UTC

    I would not trust file extensions; File::MMagic seems to me a better solution; here is an untested snippet:

    use File::MMagic; $mm = new File::MMagic; # use internal magic file # disable checks made against file extension $mm->removeFileExts; $type = $mm->checktype_filename("/somewhere/unknown/file"); ...

    $type will contain a MIME mediatype string.

    HTH, Valerio

      I'm not familiar with that. I'll look into it.

      Thanks!
      _____________________________________________________
      mojobozo
      word (wrd)
      interj. Slang. Used to express approval or an affirmative response to
      something. Sometimes used with up. Source

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2015-07-05 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls