Downloading More than 1 File via HTTP

They have: 82 posts

Joined: Oct 2001

I need to download a number of files depending on how many were checked with checkboxes. I have the following script which determines which items were checked.

<script LANGUAGE="JavaScript">
function getSelected(opt) {
var selected = new Array();
var index = 0;
for (var intLoop = 0; intLoop < opt.length; intLoop++) {
if ((opt[intLoop].selected) ||
(opt[intLoop].checked)) {
index = selected.length;
selected

= new Object;
selected

.value = opt[intLoop].value;
selected

.index = intLoop;
}
}
return selected;
}

function outputSelected(opt) {
var sel = getSelected(opt);
var strSel = "";
for (var item in sel)
strSel += sel[item].value + "\n";
//alert("Selected Items:\n" + strSel);
document.mimeType=strSel;
}
</script>

The problem is how do I download these files? There will be a dialog box saying "would you like to download" or whatever. At this point I have left the function on this page.

Should I handle this through ASP?

Any Ideas?

Thanks!

- Mike

Blessed is the man who fears the LORD, who delights greatly in his commandments. Psalms 112:1

They have: 447 posts

Joined: Oct 1999

i would suggest either

a: making users download files individually
or
b: zipping files int collections that can be downloaded

what you want to do is certainly possible, but you're adding a ton of complexity by allowing them to pick any to download at once.

first thing that comes to my mind is this:

user selects say 3 files and clicks 'download'. a cgi script starts the download of file1, and a form submitted to the same script url with files 2 and 3 as hidden fields. the form is submitted when the file is done downloading (not sure how to detect this, maybe experiment with BODY OnLoad) and the next file starts downloading. rinse and repeat until your script gets to the end of the download list.

a quick but sloppy alternative would be to open and minimize a new window with js for each file selected, and download them all simultaneously.

also you may want to check into php's ftp functions. ive never used them so im not sure the extent of their functionality, id guess they only facilitate transfers between a ftp server and the webserver but ive been surprised by phps built in functionality many times before.

They have: 447 posts

Joined: Oct 1999

another method, again while rather sloppy but simple, would be to add a bunch of hidden frames and when a user selects multiple files set the location of the hidden frames to the specified files. The user will get a download confirmation box but no windows will popup and they wont be able to see the frames where the download is taking place.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

This is going to be a tough nut to crack without some sort of applet/control on the client-side. I think SoftArtisans make a control that does what you describe, check out JFile/XFile at their website: http://www.softartisans.com/softartisans/index.html

PJ | Are we there yet?
pjboettcher.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.