Hi Everyone, I'm writing a program that allows people to send emails with attachments via a web page. It stores these attachments encoded on the hard disk like they would look in the final text file that gets send.
For some reason, IE and Opera isn't reading a value from the $cgi->upload but Netscape (on PC and Red Hat) and Mozilla seem to be able to. The server is the same Red Hat machine and I'm running Apache (duh!) :-) Could anyone suggest to me what is going wrong and how to fix it? Thanks, Elwyn
#!/usr/local/bin/perl use strict; use DBI; use CGI; use Time::ParseDate; use Apache::Table; use LWP::MediaTypes qw(guess_media_type); use MIME::QuotedPrint; use MIME::Base64; use Mail::Sendmail 0.75; # doesn't work with v. 0.74! use LWP::MediaTypes qw(guess_media_type); use Text::Template; use lib '.'; #------------------------------------------------------------------------------- sub store_attachments { my $cgi = shift; my $session = shift; my $temp = shift; my %param = %{$temp}; my @attach_list = @{$param{attach_list}}; unless(($cgi->param("attachment_file")) && ($cgi->param("attachment_file") ne "") ) { $param{attach_result} = "OK: No Change"; return %param; } my $attachment_file = $cgi->upload("attachment_file"); # my $attachment_file = $cgi->param("attachment_file"); if (grep (/$attachment_file/, @attach_list)) { $param{attach_result} = "<p><font class=\"notsosmall\">Error: You tried to upload the file '$attachment_file' as the attachment file. There is already a file with that name. Remove the other file before trying to upload this one again.</font></p>\n"; return %param; } # THIS IS WHERE THE CODE REALISES THAT NOTHING IS BEING SET if (!(defined($attachment_file)) || ($attachment_file =~ /^\s*$/) ) { $param{attach_result} = "OK: No Change"; return %param; } # This code reads and encodes the filehandle print "<h1>VALUE IS: " . $attachment_file . "</h1>"; binmode $attachment_file; undef $/; my $encoded = encode_base64(<$attachment_file>); if ($encoded eq "") { $param{attach_result} = "<p><font class=\"notsosmall\">Error: You selected the file '$attachment_file'. It has a zero file size or wasn't uploaded successfully.</font></p>"; return %param; } my @bits = split( /\//,$attachment_file); my $fileshort = $bits[ ($#bits) ]; # File name without path my $type = guess_media_type($fileshort); my $filepath = TEMP_MAIL_DIR . $session->SID . "_attachment_" . $fileshort; unless (open (MFILE, ">$filepath")) { $param{attach_result} = "<p><font class=\"notsosmall\">Error: Couldn't open the file '$filepath' for writing: $!</font></p>\n"; return %param; } print MFILE <<EO_ATTACH; Content-Type: $type; name="$fileshort" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="$fileshort" $encoded EO_ATTACH close(MFILE); push (@attach_list, $fileshort); $param{attach_list} = \@attach_list; $param{attach_result} = "OK: New File Saved"; return %param; }
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]