Solved

Multiple file download

Posted on 1998-10-28
12
199 Views
Last Modified: 2013-12-25
How can I supply a link which will download multiple files? E.g. I have two GIFs and want to download them both in one go from the same link/button.
0
Comment
Question by:BOINGED
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
12 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 100 total points
ID: 1855961
Gifs will not download (they get displayed in the browser) but if you want to load them into cache, the following should do it:
<SCRIPT>
function loadImages() {
   if (!document.images) return; // IE3 does not support this
   Image1 = new Image(); Image1.src = 'image1.gif';
   Image2 = new Image(); Image2.src = 'image2.gif';
}
</SCRIPT>
<A HREF="javascript:loadImages()">Cache two images</A>


0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855962
Alternatively try this:
<HTML>
<HEAD>
<SCRIPT>
function loadImages() {
   var Text = '<IMG SRC="image1.gif"><IMG SRC="image2.gif">'
   top.imageframe.document.open();
   top.imageframe.document.write(Text);
   top.imageframe.document.close();
}
</SCRIPT>
</HEAD>
<FRAMESET ROWS="10%,*">
<FRAME NAME="linkframe" SRC="test.htm">
<FRAME NAME="imageframe" SRC="javascript:' '">
</FRAMESET>
</HTML>

and in test.htm have
<A HREF="javascript:top.loadImages()">Load two images</A>

Hope this helps,

Michel
0
 

Author Comment

by:BOINGED
ID: 1855963
Thanks for your prompt reply, however I may have been unclear with my question, what I want to do is to enable a user to download two files, not neccessarily GIFs, to their hard disk with the click of a single button. Like when you press shift & click on a html link it will save/download the html file, but I need it for, say, multiple html files.
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855964
I understand, however you cannot force a download of files that the browser thinks it can display so gif, jpg, txt and so on can only be downloaded with a browser specific action like shift-click or right-click+save-as.
Zipped files and executables are different and you have some more possibilities:
1. one click loads two files into separate frames, that should trigger two save-as prompts
2. one click executes a server based function that zips the two files and returns them

1:
<HTML>
<HEAD>
<SCRIPT>
function loadTwo() {
   top.hidden1.location='file1.zip';
   top.hidden2.location='file2.zip';
}
</SCRIPT>
</HEAD>
<FRAMESET ROWS="100%,*,*>
<FRAME NAME="contents" SRC="normal.htm">
<FRAME NAME="hidden1" SRC="javascript:' '">
<FRAME NAME="hidden2" SRC="javascript:' '">
</FRAMESET>
</HTML>

and in normal.htm have
<A HREF="javascript:loadTwo()">Download two files</A> please answer OK when prompted to save...

Michel
0
 
LVL 28

Expert Comment

by:sybe
ID: 1855965
michel,
that's a clever approach. I wonder if you really need a frameset for this.

What about just a plain page:
====
<html>
<head>
<script>
function DownloadFiles() {
  document.location = 'zipfile1.zip';
  document.location = 'zipfile2.zip';
}
</script>
</head>
<body onload="DownloadFiles()">
</body>
</html>
=====

since the zips are not displayed, the original HTM page remains in the window. I've gotta try this out !
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855966
Sybe: In my experience it must be in two different frames or one frame and a timeout, but the timeout is hard to calculate:
function DownloadFiles() {
   top.otherframe.document.location = 'zipfile1.zip';
   setTimeout("top.otherframe.document.location = 'zipfile2.zip'",100000);
}

If the onLoad could be used, the second download could be initiated onLoad, but I believe this even is triggered almost immediately if it is a non-displayable file

Let me know what you find...

Michel
0
 

Author Comment

by:BOINGED
ID: 1855967
I tried your solution Michel and after I fixed the bugs :) got it working in IE4 but not Communicator 4.5 - is that just due to Netscape's DOM being different to Microsofts?
sybe your solution doesn't work - only the second file is ever downloaded.
Thanks for your assistance, will grade soon if there are no more comments.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1855968
I found some weird code that works in one document. It does not work in IE3. But it works in NS3, as long as the files that should be downloaded are are present on the server.

<html>
<head>
<script>

strEmpty = '';
arrFiles = new Array('zipfile1.zip', 'zipfile2.zip', 'zipfile3.zip', 'zipfile4.zip');
myLinks = new Array();

for (i=0;i<arrFiles.length;i++){
  myLinks[i] = strEmpty.link(arrFiles[i]);
  document.write(myLinks[i]);
}
for (i=0;i<arrFiles.length;i++){
  if (document.links) {
    document.location.href = document.links[i];
  }
}
</script>
</head>
<body bgcolor="#FFFFFF"">


</body>
</html>


0
 
LVL 28

Expert Comment

by:sybe
ID: 1855969
There are some weird things to the code:

1. it creates invisible links
2. it redirects the document to the url of a link without an event.

Hmm, somehow I don't think that Javascript was made for this :). But it's fun trying.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855970
I cannot see the DOM make any difference unless you use document.all or something...
Would you care to paste the code that works in IE but not Netscape?

Michel

0
 

Author Comment

by:BOINGED
ID: 1855971
This is weird. this code actually works in Netscape but not IE.

test.htm contains:

<HTML>
<HEAD>
<SCRIPT>
function loadTwo()
{
top.hidden1.location='file1.zip';
top.hidden2.location='file2.zip';
}
</SCRIPT>
</HEAD>
<FRAMESET ROWS="100%,*,*">
<FRAME NAME="contents" SRC="normal.htm">
<FRAME NAME="hidden1" SRC="javascript:' '">
<FRAME NAME="hidden2" SRC="javascript:' '">
</FRAMESET>
</HTML>

and normal.htm contains:

<A HREF="javascript:top.loadTwo()">Download two files</A> please answer OK when prompted to save...

I'll try the sybe's weird code but I think I'll go for a self-extracting archive, damn now I've got to register pkzip :)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1855972
Very strange... Could you please try the following before discarding IE:
top.hidden1.location='http://www.myserver.com/file1.zip';
top.hidden2.location='http://www.myserver.com/file2.zip';

changing the http://www.myserver.com/ for the location of the files...
Also change the 100%,*,* to
33%,33%,*
so you can see any webserver messages

If that does not work, please try

top.hidden1.location='http://www.myserver.com/file1.zip';
setTimeout("top.hidden2.location='http://www.myserver.com/file2.zip'",3000);

just for fun...

the zip files should come from the server, not from harddisk...

Michel

0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ebay messages api 6 43
Wordpress Security 29 111
Designing forms 3 70
WordPress:  Reset File Permission after server migration 5 65
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question