Nikola Knezevic wrote:
>
> Dana 30.01.01, Paul Popour napisa:
>
> > > > But, what to do if there are more file-upload fields???
> > > > Simple solution is to repeat above algorhythm for every file. No so
> > > > elegant... Is there a better way to accomplish the same thing????
>
> > I believe the proper format for multi-file attachments in Mail::Sender is
> > $output = "$file1, $file2, $file3";
> > ref ($sender = new Mail::Sender({from => $from,
> > smtp => $smtp})) or die "$Mail::Sender::Error\n";
> > (ref ($sender->MailFile({to =>$recipients, subject => $subject, msg =>
> > $msg, file => $output }))
> > and print "Mail sent OK.\n") or die "$Mail::Sender::Error\n";
> > }
>
> OK, I know that. But the problem is (once more):
> CGI passes file-handle to file that is uploaded (and I expect it isn't on
> the systems' file-system. Mail::Sender expects filename. How to connect
> these two?? Option is to create tempfile, flush from the filehandle to
> tempfile and finally add that file to message. Then, repeat this for every
> file. (message than has mult attachments). But, I want to skip 'flush from
> filehandle to tempfile' and pass FH directly to Mail::Sender::SendFile.
$tmpfilename = $cgi->tmpFileName($filename);
should get you the temp filename that CGI used.
> BTW, is there some module for creating temp files. (something like mk_temp
> in linux)???
perlfaq5:
How do I make a temporary file name?
Use the `new_tmpfile' class method from the IO::File module to get a
filehandle opened for reading and writing. Use this if you don't need to
know the file's name.
use IO::File;
$fh = IO::File->new_tmpfile()
or die "Unable to make new temporary file: $!";
Or you can use the `tmpnam' function from the POSIX module to get a
filename that you then open yourself. Use this if you do need to know
the file's name.
use Fcntl;
use POSIX qw(tmpnam);
# try new temporary filenames until we get one that didn't already
# exist; the check should be unnecessary, but you can't be too careful
do { $name = tmpnam() }
until sysopen(FH, $name, O_RDWR|O_CREAT|O_EXCL);
# install atexit-style handler so that when we exit or die,
# we automatically delete this temporary file
END { unlink($name) or die "Couldn't unlink $name : $!" }
# now go on to use the file ...
If you're committed to doing this by hand, use the process ID and/or the
current time-value. If you need to have many temporary files in one
process, use a counter:
BEGIN {
use Fcntl;
my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
my $base_name = sprintf("%s/%d-%d-0000", $temp_dir, $$, time());
sub temp_file {
local *FH;
my $count = 0;
until (defined(fileno(FH)) || $count++ > 100) {
$base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
sysopen(FH, $base_name, O_WRONLY|O_EXCL|O_CREAT);
}
if (defined(fileno(FH))
return (*FH, $base_name);
} else {
return ();
}
}
}
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles http://www.todbe.com/
/ ) /--< o // // Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_ http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users