#!/usr/bin/perl -w # # test.cgi -- A CGI script for FileUpload module demonstration. # Make sure FileUpload.pm has been installed before # you start to test this script. # This script reads input from "./form.html" file, # it expects there is a file being uploaded with # input field name, ufile. # # Simon Tneoh Chee-Boon tneohcb@pc.jaring.my # # Copyright (c) 2000-2002 Simon Tneoh Chee-Boon. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # use strict; use vars qw($cgi $fu $sizewritten); # Autoflush. $| = 1; # Print the HTTP header line. # I am not using CGI->header here because I want to check if CGI # version 2.46 or above is installed. print "Content-Type: text/html\n\n"; # Make sure CGI version 2.46 or above is installed. eval("use CGI 2.46 qw(-private_tempfiles :standard);"); (print("Error: $@"), exit(-1)) if $@; # Make sure FileUpload is installed. eval("use FileUpload 0.07;"); (print("Error: $@"), exit(-1)) if $@; # Create CGI object. $cgi = new CGI; # Has any files been uploaded? if (! $cgi->param('ufile')) { print <<__END__ERROR__; Error It seems like you have not selected any files yet. Please try again. __END__ERROR__ exit(-1); } # Create the FileUpload object. $fu = new FileUpload($cgi->param('ufile')); if (! $fu) { print <<__END__ERROR__; Error Failed to create FileUpload object. Please try again. __END__ERROR__ } # Print results. print <<__END__HTML__; Upload Result

Upload Result

[ Back To Index | Back To Demonstration Page ]
Action Command Returns
Original filename \$fu->orig_filename ${\$fu->orig_filename}
Original filepath \$fu->orig_filepath ${\$fu->orig_filepath}
Extensions denied \$fu->deny_ext ${\sprintf("%s", join(",", $fu->deny_ext))}
Add extensions denied \$fu->deny_ext('cgi', 'shtml') ${\sprintf("%s", join(",", $fu->deny_ext('cgi', 'shtml')))}
Extensions denied \$fu->deny_ext ${\sprintf("%s", join(",", $fu->deny_ext))}
Characters allowed \$fu->allow_char ${\sprintf("%s", join(",", $fu->allow_char))}
Save the file
(For security problem, we only demo save_as() here.)
\$fu->save_as("./test.html") __END__HTML__ # Try to save the uploaded file. $sizewritten = -1; if (!($sizewritten = $fu->save_as("./test.html"))) { print "Fail to save file: $!"; } else { print $sizewritten."bytes written
\n"; } print <<__END__HTML1__;
Add characters allowed \$fu->allow_char('#\/', '\,') ${\sprintf("%s", join(",", $fu->allow_char('#\/', '\,')))}
Characters allowed \$fu->allow_char ${\sprintf("%s", join(",", $fu->allow_char))}
Current FILEHANDLE position \$fu->get_pos ${\$fu->get_pos}
Set FILEHANDLE position \$fu->set_pos(255) ${\$fu->set_pos(255)}
Read a line \$fu->get_line ${\$fu->get_line}
Current FILEHANDLE position \$fu->get_pos ${\$fu->get_pos}
File size \$fu->size ${\$fu->size}
Save the file
(For security problem, we only demo save_as() here.)
\$fu->save_as("./test.html") __END__HTML1__ # Try to save the uploaded file. $sizewritten = -1; if (!($sizewritten = $fu->save_as("./test.html"))) { print "Fail to save file: $!"; } else { print $sizewritten."bytes written
\n"; } print <<__END__HTML2__;
Check the uploaded file ./test.html (Notice: Because this script always save the uploaded file to "./test.html", so you might see file that's uploaded by others.)

[ Back To Index | Back To Demonstration Page ] __END__HTML2__ # Done. exit(0); __END__