in reply to upload PDF files
#!/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"))'
|
|---|