On 02/23/2007 09:06 AM, Zembower, Kevin wrote:
Mumia, I don't think the problem is in sending the file out. When the
file is recorded on /tmp/, its size is zero. The files I'm uploading are
at least 1KB. Something's wrong with reading the file from the uploaded
filehandle, I believe. Your example takes for granted a properly written
file on disk, and doesn't include reading an uploaded file from a
filehandle. I have other scripts that send out files as attachments
using MIME::Lite, so I'm somewhat confident in this part of my script.
Thanks, though, for taking the time and effort to try to help me with my
problems.
-Kevin
Yeah, I should've read your message more closely, sorry.
open(TMP_FILE, ">$tmp_file_name") or die "Can't open temp upload file
$tmp_file_name\n";
my $fh = $query->upload('Material_File');
while (<$fh>) {
print TMP_FILE;
} # while there's more file to upload and store
close(TMP_FILE);
You've already mentioned that you're on a UNIX system, so setting
binmode to raw shouldn't matter, but I suggest covering all the bases
anyway:
open (TMP_FILE, ">:raw", $tmp_file_name) or die "Can't open temp upload
file $tmp_file_name: $!";
print TMP_FILE <$fh>;
close(TMP_FILE);
However, I don't see a reason to save the data to a file at all. Why not
just slurp the data directly from the file handle? Here is an example
that doesn't send the mail:
use strict;
use warnings;
use CGI::Pretty qw(-no_xhtml :standard);
url_param('posted') ? process() : request() ;
sub request {
print header(
-type => 'text/html',
'-cache-control', 'no-cache',
);
print start_html('Upload File'),
h1('Upload File'),
p('Use this page to test uploading a file.') ;
print start_form('POST',
url(-relative => 1) . '?posted=1',
'multipart/form-data'),
p('Enter the path to your file to upload here:'),
p(filefield('test-upload','',10,4000)),
submit,
end_form;
print end_html;
}
sub process {
require MIME::Lite;
print header(
-type => 'text/plain',
'-cache-control', 'no-cache',
);
my $fh = param('test-upload');
return unless $fh;
my $mime = MIME::Lite->new(
From => '[EMAIL PROTECTED]',
To => '[EMAIL PROTECTED]',
Subject => 'Test of File Upload',
Type => 'text/plain',
Data => do { local $/; <$fh> },
);
print "\n";
print $mime->as_string;
}
__HTH__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/