Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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;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

In reply to CGI.pm woes with multipart attachments by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-26 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found