in reply to upload PDF files

In addition to the excellent link provided by Tommy above, I would direct your attention to the CGI::Upload module which is designed to facilitate the uploading of files via HTTP. This module incorporates methods for verifying the content and MIME-type of the uploaded file - For example, the following code incorporates a check to ensure that the uploaded file is a PDF file:

#!/usr/bin/perl -Tw use CGI; use CGI::Carp qw/ fatalsToBrowser /; use CGI::Upload; use IO::File; use strict; my $upload = CGI::Upload->new; if ( defined $upload->file_name('userfile') ) { unless ( $upload->mime_type('userfile') eq 'application/pdf' ) { # Error handling to be incorporated here which will be trigg +ered if the # uploaded file is _not_ a PDF file die "Uploaded file is not a PDF document file"; } # Open the output binary file stream my $output = IO::File->new( $upload->file_name('userfile') ); die $! unless defined $output; binmode( $output ); # Read the file data from the uploaded file stream and write thi +s data to the # output file stream my $buffer = ''; my $input = $upload->file_handle('userfile'); while ( read( $input, $buffer, 1024 ) ) { print $output $input; } $output->close; chmod 0777, $upload->file_name('userfile'); }

Further to this, another example of the usage of CGI::Upload can be found here.

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000001000100000"))'