tags:

views:

32

answers:

3

I currently submit a form on to an invisible iframe. The action file creates a CSV which is automatically downloaded. Is it possible to have multiple files downloaded when the form is submitted?

+1  A: 

I don't think that it is possible to do without having a custom download manager on the client side. You could technically insert them into the response stream to the client, but they wouldn't understand how to handle it.

I have always just created a zip file with all the files in it and sent that to the client. Wouldn't work if you are trying to display them in the browser or something like that, but I don't know what your goal is on the client so I thought that it might work for you.

Brian ONeil
Thanks, the zip idea works great!
Brian
+1  A: 

Yes, the following code does what you want, with some modification. Note, very much not my code and it requires javascript be enabled.

function makeFrame( url ) 
{ 
    ifrm = document.createElement( "IFRAME" ); 
    ifrm.setAttribute( "style", "display:none;" ) ;
    ifrm.setAttribute( "src", url ) ; 
    ifrm.style.width = 0+"px"; 
    ifrm.style.height = 0+"px"; 
    document.body.appendChild( ifrm ) ; 
}  

function downloadFiles( )
{
   makeFrame('urlof/file1.csv');
   makeFrame('urlof/file2.csv);
}
Serapth
This is possible, but I read the question as "have them downloaded from the post operation" You could have the client call back to get the files if the POST generates something on the server for the client to come back to get. Just not how I read the question. Brian, what you trying to do?
Brian ONeil
A: 

No, that is not possible. Each response can only contain one file. You need one request for each file that you want to download.

Guffa