Simple way to compile external linked files

Discussion in 'Web Design and Development' started by chrispholt, Sep 1, 2012.

  1. chrispholt macrumors regular

    Joined:
    Feb 6, 2010
    Location:
    Cheddar, UK. Yes where the cheese comes from..
    #1
    Hi,

    I was wondering if anybody could help me with a website I am making. I am quite capable of making websites (fairly simple ones) but know nothing about php and databases etc.

    I have this test page, http://pastpapercentre.co.uk/test/coursetest.html and under the sub-heading "Pastpapers" there are is a listed of linked .pdf documents.

    My website basically links documents from other websites, making it easy to access.

    THE QUESTION

    Is there an easy/simple way for me to make a download all button (like already on the site) compile all of the linked files into a .zip and then be presented as a download to the user. I will be making the website in a fairly "manual" manner, without databases.

    So is there a way to make some sort of php script download all link files in one div or something? (complete long shot)

    Any tips will be appreciated.

    Thanks
     
  2. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #2
    You asked for simple, so I assume you only need the code necessary to create the zip archive and set the headers to start the download on the fly. Meaning, you know how to get the list of documents to add the zip.

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

    Read that page and all comments there, download the source there and once you create your list pass it to the function something like this:

    PHP:
    $file_names=array('test.php','test1.txt');
    $archive_file_name='zipped.zip';
    $file_path=dirname(__FILE__).'/';
    zipFilesAndDownload($file_names,$archive_file_name,$file_path);
    That's pretty damned simple.

    Up to you to add sensible code to deal with issues such as multi-user or sessions, checking paths, permissions, dealing with thousands of files, etc.

    Note: PHP 5.2.0 or later to avoid installing a library to support ZIP

    -jim
     

Share This Page