#!/usr/bin/perl -w
#
# Perl script to accept file uploads. This script is provided for demonstration
# purposes only.
# you need to have the CGI module installed.
#
# Copyright Rad Inks (pvt) 2003
# http://www.radinks.com
#
# This is a sample file upload handler script that demonstrates how files
# can be accepted or rejected based on it's extension.
#
# You can define a list of allowed types in the $allowed array, only files
# with matching extensions will be accepted. Alternatively you can define
# a list of file types to be rejected using the $reject array. Any file with
# a matching extension will be rejected while all other file types will be
# considered safe.
#
# If both $allow and $reject are defined, $accept takes precedence. Please use
# lower case extensions.
#
use CGI;
use Carp;
sub bye_bye {
$mes = shift;
print "
$mes
\n";
exit;
}
print "Content-type: text/html\n\n ";
my $cg = new CGI();
#
# Files will not be saved if $save_path is left undefined. Please make sure
# the path you choose is writable. And don't forget the trailing '/'
#
my $save_path='/tmp/junk/';
#
# enter a list of file extensions that should be rejected.
#
my @reject =('html','exe','com','bat','dll','sh','php','cgi','class');
#
# If $accept array is defined only files with matching extensions
# are allowed.
#
# @accept = array('gif');
#
print <<__TABLE__;
| Files Uploaded | ||
| $filename | \n"; print "$fsize | \n"; # # extracts the extension and converts it to lower case. # my @parts = split('\.',$filename); my $ext = $parts[$#parts]; $ext =~ tr/A-Z/a-z/; carp $ext; if(@accept) { foreach(@accept) { if($_ eq $ext) { print'rejected | rejected | '; next CONT; } } } # # if we have reached this stage that means the file has passed the test # open (OUTFILE,">>$save_path/$filename"); while(<$fh>) { print OUTFILE $_; } close(OUTFILE); print 'accepted | '; } } print <<__TABLE__;
Sample Perl Upload handler provided by Rad Inks
have you seen our Secure FTP Applet or our Multimedia Messaging Solution?
__TABLE__