最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Download multiple files from one link - Stack Overflow

programmeradmin1浏览0评论

I would like to open multiple download dialog boxes after the user clicks on a link.

Essentially what I am trying to do is allow the user to download multiple files. I don't want to zip up the files and deliver one zipped file because that would require a lot of server resources given that some of the files are some what large.

My guess is that there may be some way with javascript to kick off multiple requests when the user clicks on a certain link. Or maybe there might be a way on the server side to start off another request.

I would like to open multiple download dialog boxes after the user clicks on a link.

Essentially what I am trying to do is allow the user to download multiple files. I don't want to zip up the files and deliver one zipped file because that would require a lot of server resources given that some of the files are some what large.

My guess is that there may be some way with javascript to kick off multiple requests when the user clicks on a certain link. Or maybe there might be a way on the server side to start off another request.

Share asked Aug 9, 2009 at 20:21 DarwynDarwyn 4,8043 gold badges27 silver badges28 bronze badges 4
  • 8 Dear god, I hoping that I'm not one of your users! – Henrik P. Hessel Commented Aug 9, 2009 at 20:24
  • I can't be sure, but this scenario seems unlikely with modern browsers. Also, somewhat confusing for the user. – spender Commented Aug 9, 2009 at 20:24
  • @rAyt I proposed the zipped file solution but the client seems wary about using server resources to zip files together. Maybe I'll reply back with some benchmarks to alleviate his fears. – Darwyn Commented Aug 9, 2009 at 22:53
  • Unless they're running some seriously old hardware or dealing with really high traffic volume, I'm willing to bet their server will be able to handle it. – MattC Commented Aug 10, 2009 at 2:54
Add a ment  | 

5 Answers 5

Reset to default 4

Unless the client is configured to automatically download files, you can't acplish this without packaging the files in a single response (like ZIP solution you mentioned.) This would be a security issue if a Web site would be able to put arbitrarily large number of files on your disk without telling you.

By the way, you might be overestimating the cost of packaging in a single file. Streaming files is usually an I/O-bound operation. There should be enough CPU cycles to spare for piping the data through some storage(tar)/pression(zip) methods.

If you absolutely, positively cannot zip at the server level, this would probably be a good instance for creating some sort of custom "download manager" client-side plugin that you would have the user install and then you could have plete control over how many files you downloaded, where they went, etc.

I suppose you could link to a frameset document or a document containing iframes. Set the src of each from to one of the files you want to download.

That said, a zipped version would be better. If you are concerned about the load then either:

  • zip the files with pression set to none
  • use caching on the server so you zip each group of files only once
  1. Present a page with a form of check boxes of the available files for download - with multiple select enabled for the check boxes.
  2. User selects multiple files and submits forms.
  3. Server accepts request and creates a page with serial-triggered file download javascript.
  4. The page with the embedded javascript is presented to the user's browser, listing and asking for confirmation the files to be serially downloaded.
  5. User clicks [yes - serially swamp my harddisk with these files] button.
  6. foreach file, listener for download pleted triggers the next download, until end of list.

I only know how to do this using Google GWT, where I had set up GWT RPC between browser and server. Took me two weeks to understand GWT RPC and perfect the download. Now it seems rather simple.

Basically (do you know basically is one of the most used non-technical words among the geek munity?), you have to declare a server service class specifying the datatype/class of transfer. Where the datatype must implement serializable. Then on the browser-side the GWT client declares a corresponding receiver class specifying the same serializable datatype. The browser side implements a listener for onSuccess and onFailure.

Hey, I even managed to augment GWT service base class so that I could use JSP rather than plain servlets to implement the service interface.

Actually, I was not downloading a series of files but streams that conditionally serially triggered the next stream, because my onSuccess routine would inspect the current stream to decide what content to request for on the next stream.

Ok, two weeks was an exageration, it took me a week to do it. A genius would have taken half a day only.

I don't see what the big deal is with this. Why not something like this:

<a href="javascript:" id="myLink">Click me</a>

<script type="text/javascript">
$('a#myLink').click(function() {
    window.open('http://www.mysite./file1.pdf', 'file1');
    window.open('http://www.mysite./file2.pdf', 'file2');
    window.open('http://www.mysite./file3.pdf', 'file3');
});
</script>
发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>