#!/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 triggered 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 this 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'); }