Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Using Perl to Output Multiple Files for Download via a Browser

by Loops303 (Novice)
on Mar 06, 2013 at 16:33 UTC ( #1022031=perlquestion: print w/replies, xml ) Need Help??
Loops303 has asked for the wisdom of the Perl Monks concerning the following question:

I am building a web form for a user to upload a csv file, check off what outputs they want (e.g., Report 1, Invoice, etc.) and then the script grabs the upload form and is supposed to spit out the various things they checked off as individual CSV files.

My problem is I can output to 1 single CSV, not multiple ones.

I've tried

print "Content-Type: multipart/mixed\n"; print "Content-disposition: attachment;filename=test.csv\n\n";

Which works to output the fist file.

For the next file, I've tried to start with the same above (with filename=test2.csv) or just the Content Disposition with a new filename.

The goal is to output test.csv and test2.csv.

What happens instead is it prints the content intended for test2 into test.csv.

Any advice on how to proceed will be much appreciated!

Thank you!

Replies are listed 'Best First'.
Re: Using Perl to Output Multiple Files for Download via a Browser
by daxim (Chaplain) on Mar 06, 2013 at 16:41 UTC
    Solution 1: Stream the CSV outputs into an archive (Archive::Zip), then create a response with the archive.

    Solution 2: Write the CSV outputs into separate temporary files, then create a response with a HTML document linking to the files.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1022031]
Approved by tmharish
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2018-03-20 12:36 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (251 votes). Check out past polls.