Options for downloading linked files?

Discussion in 'Web Design and Development' started by irishgrizzly, Nov 29, 2010.

  1. irishgrizzly macrumors 65816

    irishgrizzly

    Joined:
    May 15, 2006
    #1
    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?
     
  2. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #2
    There might be some security restrictions to forcing multiple file downloads. You might try to set up a server side function to take all the checked files, zip them on the server, and download one zipped file containing all the files that were checked. Here's a possible solution I found by googling "php + zip files on server for download"

    http://roshanbh.com.np/2008/09/force-download-mutiple-files-zip-archive-php.html
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    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()
    {
      
    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>
     

Share This Page