CGI file upload example : File Upload « CGI « Perl






CGI file upload example

    


#!/usr/local/bin/perl

use CGI;

$co = new CGI;    

if (!$co->param())
{
    print 
        $co->header,
        $co->start_html('CGI File Upload Example'),
        $co->center
        (
            $co->start_multipart_form,
            $co->filefield(-name=>'filename', -size=>30),
            $co->br,
            $co->submit(-value=>'Upload'), 
            $co->reset,

            $co->end_form

    ),
    $co->hr;
} else {
    print 
        $co->header,
        $co->start_html('');
    $file = $co->param('filename');
    @data = <$file>;
    foreach (@data) {
        s/\n/<br>/g;
    }
    print 
        $co->center($co->h2("Here's the contents of $file...")),
        "@data";
}
print $co->end_html;

   
    
    
    
  








Related examples in the same category

1.Checking for Acceptable File Types
2.Printing the Content-Type of an Uploaded File