edwardra3 has asked for the wisdom of the Perl Monks concerning the following question:
Cutting out the irrelevant code, I have:
#!/usr/bin/perl -wT use strict; use CGI qw/param uploadInfo/; use CGI::Carp qw ( fatalsToBrowser ); use File::Basename; my $query = new CGI; my $filename = $query->param("manuscript"); my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); $filename = $name . $extension; my @allowedext = qw(doc docx odt rtf); unless(@allowedext = $extension) { print $query->header ( ); print "Filetype not allowed. Please upload doc, docx, odt, or rtf fil +es only."; exit; }
Any ideas what I'm doing wrong?
Update: Oops, I guess I stripped out too much! In the full script, $name and $extension are initialized. Updated the code above to include it. The unless($allowedext{$extension}) was someone else's suggestion. It was originally unless($extension = @allowedext) I've changed and overwritten so much, I forgot that that piece of code didn't work. When running the script successfully, but without the extension check stopping the upload of an unacceptable filetype, I had resorted to the original piece of code, which is now reflected above.
Update 2: It ain't pretty, but I got it working. I still don't know what I couldn't get map to work on my webhost, but this gets around that issue.
if (lc $extension ne ("doc" "docx" or "odt" or "rtf")) { print "Filetype '$extension' not allowed. File extension must be: do +c, docx, odt, or rtf"; exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: extension check on upload script doesn't do anything
by toolic (Bishop) on Feb 23, 2011 at 03:31 UTC | |
|
Re: extension check on upload script doesn't do anything
by toolic (Bishop) on Feb 23, 2011 at 15:30 UTC | |
by edwardra3 (Initiate) on Feb 23, 2011 at 18:15 UTC | |
|
Re: extension check on upload script doesn't do anything
by GrandFather (Saint) on Feb 23, 2011 at 03:32 UTC | |
|