in reply to Checking File Types
For example, using the CGI::Upload module, this code could be reduced to the following (comments included for explanation) :
use CGI; use CGI::Upload; my $cgi = CGI->new; my $upload = CGI::Upload->new; # The array @types contains a list of allowed file # extensions - Note that testing a file by MIME type is # more secure than depending upon the file extension # alone. my @types = qw/ gif jpg jpeg jpe jfif /; # Loop through each of the image upload fields. The # image field names are being used here in place of the # loop index - This has been written thus so that # additional image upload fields, which may not # necessarily be named 'im<num>' can be added. foreach ( qw/ im1 im2 im3 im4 im5 / ) { # Ensure that the CGI parameter has been defined if ( $cgi->param($_) ) { # Check the file type of the uploaded file with the list # of allowed file types in @types (grep works nicely # for this) - If the image file extension is not within # the array @types then return an error to the user. unless ( grep /\Q$upload->file_type($_)\E/ @types ) { error('Your image needs to be in GIF or JPEG format'); } } }
perl -e 'print+unpack("N",pack("B32","00000000000000000000000111001011")),"\n"'
|
---|