#!/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
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/';
print <<__TABLE__;
| Files Uploaded |
| File Name |
File size |
__TABLE__
my $size = $cg->param;
my $userfile_parent = $cg->param('userfile_parent');
#
# attempt to loop through the list of files.
#
for($i=0 ; $i < $size ; $i++)
{
$file_upload = $cg->param("userfile[$i]");
if($file_upload) {
my $fh = $cg->upload("userfile[$i]");
my $filename;
my $fsize;
$fsize =(-s $fh);
if(defined($save_path))
{
#
# the save path is set, let's try to save the file.
#
# In keeping with our goal of keeping these scripts as simple as
# possible, we decided not to use the File module. We will rely
# on string manipulations instead.
#
$filename = $fh;
$filename =~ s/$userfile_parent//;
@name = split('/',$filename);
$filename= pop(@name);
if(defined($userfile_parent))
{
my $path =$save_path;
foreach(@name)
{
$path .= "$_/";
unless(-d $path)
{
mkdir($path);
}
}
open (OUTFILE,">>$path/$filename");
while(<$fh>) {
print OUTFILE $_;
}
close(OUTFILE);
}
}
print "| $filename | \n";
print "$fsize |
";
}
}
print <<__TABLE__;
Sample Perl Upload handler provided by
Rad Inks
have you seen our Secure FTP Applet or our
Multimedia Messaging Solution?
__TABLE__