Hi all,

I'm back on the list with another upload problem that's a little baffling to me. I'm using the following script to do multiple uploads. But, after the files are uploaded, they have a file size of 0 KB. And, in the case of text files, the contents of the files are missing. ...anyone familiar with this problem? The script appears to work fine; no errors. But the files are zero size with no contents.

It looks to me that the script is not uploading the actual file, but merely writing the file name to disk in the form of an empty file.

....not sure where to start looking on this one. Does anyone have any pointers?

TIA

Ron
-----------------------------------snip-------------------------------------
#!/www/perl/bin/perl -w
use strict;
use DBI;
use File::Basename;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my $directory = "C:/www/webroot/storage";
my $url_path = "/storage";
my @file_names = param('filename');
my @descriptions = param('description');
my @file_array = ();
$CGI::POST_MAX = 1024 * 1500; # limit uploads to 1500kb of all files combined
Get_Names();
Store_Descriptions();
Print_Results();
sub Get_Names{
my $counter = 0;
my $full_name;
my $file_name;
foreach $full_name (@file_names) {
my $rec = {};
if ($full_name ne "") {
$file_name = Get_File_Name($full_name);
$rec->{file_name} = $file_name;
$rec->{full_name} = $full_name;
$rec->{description} = $descriptions[$counter];
push @file_array, $rec;
Store_File($full_name, $file_name);
}
$counter++;
}
}
sub Store_Descriptions{
my $temp;
my $DBH = DBI->connect("DBI:mysql:book", "geeksatlarge");
my $sth_insert = $DBH->prepare(qq{INSERT INTO files (Description, FileName) VALUES (?,?)}) or die $DBH->errstr;
foreach $temp (@file_array) {
$sth_insert->execute($temp->{description}, $temp->{file_name});
}
$DBH->disconnect;
}
sub Get_File_Name{
if ($ENV{HTTP_USER_AGENT} =~ /win/i) {
fileparse_set_fstype("MSDOS");
}
elsif ($ENV{HTTP_USER_AGENT} =~ /mac/i) {
fileparse_set_fstype("MacOS");
}
my $full_name = shift;
$full_name = basename($full_name);
$full_name =~ s!s!_!g;
return($full_name);
}
sub Store_File{
my $file_handle = shift;
my $file_name = shift;
my $data;
my $mime = uploadInfo($file_handle)->{'Content-Type'};
open (STORAGE, ">$directory/$file_name") or die "Error: $!n";
if ($mime !~ /text/) {
binmode ($file_name);
binmode (STORAGE);
}
while (read($file_name, $data, 1024)) {
print STORAGE $data;
}
close STORAGE;
}
sub Print_Results{
my $temp;
print header;
print start_html("File Upload Example 4");
print h2("The following files were uploaded:");
foreach $temp (@file_array) {
my $link = "$url_path/$temp->{file_name}";
print <<HTML;
<pre>
<b>File Name:</b> $temp->{file_name}
<b>Description:</b> $temp->{description}
<p><b>Link to File:</b> <a href="$link">$link</a></p>
</pre>
HTML
}
print qq(n<a href="/cgi-bin/upload_multi_save_view.cgi">View Files</a>);
print end_html;
}