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"))'


In reply to Re: upload PDF files by rob_au
in thread upload PDF files by dave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.