Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

irishgrizzly

macrumors 65816
Original poster
May 15, 2006
1,461
2
I want to have a list of links to PDF or ZIP files that have individual tick boxes so multiple files can be downloaded at once. For example;

-------------------------------------------------------
example zip file 1 []
example zip file 2 []
example zip file 3 []

Download your selection
-------------------------------------------------------

What's the best way to go about this?
 
I helped someone do this, but it's involved and relies on JavaScript. Doing things server side with PHP is more direct. The JavaScript I did is filled with the other person's site info so I can't share it easily. It makes use of an iframe and iterates over the downloads based on what's checked on the page. For some reference though, here was the public discussion.

Here are some relevant code snippets.
PHP:
var dls = new Array(); // hold the various files that need downloading

// This function gets called when user request download
function RequestDownload()
{
  // Figure out what user select
  url = 'http://yourdomain.com/test2.html?file.ext';
  // Add url of download to array
  dls.push(url);
}

function DoDownloads()
{
  d = document.getElementById('dl');
  d.src = dls[0]; // download first element
  dls.shift(); // get rid of first element
  // download next item if there is one
  if (dls.length != 0) { setTimeout("DoDownloads()", 200); }
}

-------
// This goes somewhere in the body tag.
<iframe style="display:none;" id="dl" src="test2.html"></iframe>
test2.html
PHP:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Download Page</title>
<script type="text/javascript">
//<![CDATA[
window.onload = function()
{
  url = window.location.href;
  a = url.split('?');
  if (a[1] == undefined) return;
  var dl = a[1];
  if (a[2] != undefined) dl += "?"+ a[2];
  location.href = dl;
}
//]]>
</script>
</head>
<body></body></html>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.