Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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 romping around the Monastery: (7)
As of 2017-10-20 02:05 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (258 votes). Check out past polls.