Gentlemen,
I am trying to implement a web portal on an OS/390 server. The portal is
open source, uses no special modules, and uses a flat-file database. I have
everything working well, except that I cannot upload files via the script.
I have incorporated ascii-ebcdic converters into the scripts where needed,
and all my scripts run successfully with this exception. I have managed to
successfully implement guestbooks, feedback/survey forms, weblogs, and even
discussion boards (partially). The only area I cannot resolve is this one
involving file uploads. Is there something special I should be doing?
My host is running perl version 5.006001
The source for the upload page starts here:
#!/usr/local/bin/perl
require "../../config.pl";
$Data = $uploaddir;
# If you want to allow other image file types, enter them here
@jpg_extensions = ('gif', 'jpg', 'jpeg', 'GIF', 'JPG', 'JPEG', 'png',
'PNG');
@bad_extensions = ('vbs', 'exe', 'bat', 'com', 'VBS', 'EXE', 'BAT', 'COM');
##########################################################
# Set the maximum size of each file that is permitted.
##########################################################
if (@jpg_extensions) {
$max_size = $maxuploadsize;
}
else {
$max_size = $maxuploadsize;
}
############################################################################
#
# DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE
DOING
############################################################################
#
$max_num_files = "1";
$auto_rename = 1;
# This variable tells the program whether or not to over-write or
reject like
# named files. Therefore, if you upload a file with a name that
already exists
# on the server, set this value for the appropriate following results:
# 0 => Overwrite the existing file
# 1 => Leave existing file in place, serialize the name of the
new
# new file (i.e. some_book.doc, some_book1.doc,
some_book2.doc, etc)
# 2 => Reject the new file. Leaves the original file in place
and rejects
# the new file so that it is not saved.
use CGI;
$max_num_files ||= 1;
$upload_dir ||= $ENV{'DOCUMENT_ROOT'};
undef @bad_extensions if @jpg_extensions;
for(my $a = 1; $a <= $max_num_files; $a++) {
my $req = new CGI;
if($req->param("FILE$a")) {
my $file = $req->param("FILE$a");
my $filename = $file;
$filename =~ s/^.*(\\|\/)//;
#For IE
$filename =~ s/ +/\_/g;
#For Opera
$filename =~ s/\"//g;
my $proceed_type = 0;
$filetoremember = $filename;
##################################################
# Starting to check files
##################################################
if(@jpg_extensions) {
foreach(@jpg_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 1;
last;
}
}
unless($proceed_type) {
push(@was_not_good_type, $filename);
}
}
#######################################
# If it's a BAD extension.. like exe...
#######################################
elsif(@bad_extensions) {
$proceed_type = 1;
foreach(@bad_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 0;
last;
}
}
unless($proceed_type) {
push(@was_a_bad_type, $filename);
}
}
####################
# the Catch all....
####################
else {
$proceed_type = 1;
}
###################
if(($auto_rename == 2) && (-e "$Data/$filename")) {
$proceed_type = 0;
push(@rejected, $filename);
}
if($proceed_type) {
if((-e "$Data/$filename") && ($auto_rename == 1)) {
my $pick_new_name = 1;
my $fore_num = 1;
$filename =~ /^(.+)\.([^\.]+)$/;
my $front = $1;
my $ext = $2;
while($pick_new_name) {
my $test_name = $front . $fore_num . '.' . $ext;
unless(-e "$Data/$test_name") {
$pick_new_name = 0;
$filename = $test_name;
}
$fore_num++;
}
}
elsif((-e "$Data/$filename") && ($auto_rename == 2)) {
next;
}
if(open(OUTFILE, ">$Data/$filename")) {
$filetoremember = $filename;
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
if($max_size) {
if((-s "$Data/$filename") > ($max_size * 1024)) {
push(@was_too_big, $filename);
unlink("$Data/$filename");
} else {
push(@file_did_save, $filename);
}
} else {
push(@file_did_save, $filename);
}
} else {
push(@did_not_save, $filename);
}
}
}
if(@file_did_save) {
chomp(@file_did_save);
print "Location:
$pageurl/$cgi?action=uploadsuccess&yourfile=$filetoremember\r\n\r\n";
exit;
} else {
print "Location:
$pageurl/$cgi?action=uploadfail&yourfile=$filetoremember\r\n\r\n";
exit;}
}
1;
Any assistance would be greatly appreciated, as I really want to provide my
customers with a good product, and for a portal to be useful, members must
have the ability to upload and share files.
Thanks
Don L. Loveday
LMIT
CD232 Project Support Team
(303) 676-1650