Hi, recently I posted a snippet to allow multipart attachment
downloads. I generated my own headers and it works fine with
linux apache and Mozilla. Merlyn reponded, that I could also
do it with CGI.pm. Well at the time, I didn't have the latest version
of CGI.pm, which supported the sub multipart_final, so I just
shoved the script to my code collection. I recently upgraded to
the latest CGI.pm and tried Merlyn's script again, and it just
refuses to run for me. I am asking for "higher guidance" now.
My working code follows
#!/usr/bin/perl
use warnings;
use strict;
my $boundary_string = "\n" . "--End" . "\n";
my $end_of_data = "\n" . "--End--" . "\n";
my @file_list = ("test.tgz","test1.tgz","test2.tgz");
print<<EOH;
Content-type: multipart/x-mixed-replace\;boundary=End
EOH
foreach my $file (@file_list){
&amp;send_file ($file);
print $boundary_string;
}
print $end_of_data;
exit(0);
sub send_file {
my $file = $_[0];
if (open (FILE, "< $file")) {
print<<EOF;
Content-type: application/octet-stream
Content-Disposition: attachment\; filename=$file
EOF
binmode FILE;
print <FILE>;
close (FILE);
}else{print "Cannot open file $file!"}
}
############################################
merlyn's suggestion follows below:
#!/usr/bin/perl
use CGI qw(:push);
@ARGV = ("test.tgz","test1.tgz","test2.tgz");
$/ = undef;
print multipart_init();
while (<>) {
print multipart_start("application/octet-stream");
print $_;
print multipart_end();
}
print multipart_final();
########################################
When I run Merlyn's code, the filename is always
nph-download-multi, and I'm prompted to save that
filename 6 times instead of 3, and the name is always
nph-download-multi, instead of test.tgz, test1.tgz, etc.
Now I did try to add a "-filename=>$_" to the code to
get the filename to come thru, but to no avail. Also the resultant
download is 0 bytes. I've tried every combination of header
that I could think of, but no luck. So would anyone be kind
enough to post a multipart-download script , based on CGI.pm
which actually works, so I can see what I'm doing wrong?
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.