2

Its my first post in stackoverflow, so please let me know if something is wrong so I can fix it, thanks.

I have the following code in my website...

<table id="fruits">
    <tbody>
        <tr class="file" id="tr-file">
            <td class="name" id="id1"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE1</a></td>
            <td class="name" id="id2"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE2</a></td>
            <td class="name" id="id3"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE3</a></td>
            <td class="name" id="id4"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE4</a></td>
        </tr>
    </tbody> 
</table>

I know I can zip the files in cpanel or upload the files zipped and put it as a link in the page... But I want the visitor to choose which files they want to download, no force them to download all 4 files. So I searched in Google and found a useful post. (THE PROBLEM IS THAT I JUST KNOW THE BASIC OF HTML, I dont understand what he wrote) I want the visitor to select multiples files from <table id="fruits">.

Example: http://jsfiddle.net/dn3L7/

 <table id="fruits">
        <tbody>
            <tr class="file" id="tr-file">
               <input type"checkbox" id="idc1"> <td class="name" id="id1"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE1</a></td>
               <input type"checkbox" id="idc2"> <td class="name" id="id2"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE2</a></td>
               <input type"checkbox" id="idc3"> <td class="name" id="id3"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE3</a></td>
               <input type"checkbox" id="idc4"> <input type"checkbox" id=""idc1>  <td class="name" id="id4"><a class="thickbox" href="FILE-LINK">NAME-OF-FILE4</a></td>
            </tr>
        </tbody> 
    </table>

When they finish checking the files they will be able to click a button to download the zip file.

Community
  • 1
  • 1
Dominicanstan
  • 205
  • 1
  • 5
  • 7
  • 2
    This is probably too big of a question for stack overflow, you're basically asking people to write your app for you. You'll have to learn how to make forms, process the input, create a zip file and then redirect to it. Perhaps if you break the question into smaller pieces. – Gringo Suave Oct 28 '11 at 03:25

1 Answers1

3

you can take a look at ZipArchive, you would be able to create zips with that and let the user download it.

Cletus provide a really good answer there. I humbly copy his sample here

$files = array('readme.txt', 'test.html', 'image.gif');
$zip = new ZipArchive;
$zip->open('file.zip', ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();

and to stream it:

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=filename.zip');
header('Content-Length: ' . filesize($zipfilename));
readfile($zipname);
Community
  • 1
  • 1
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • Samuel Liew do you know how to create the "checkbox"? how i explain in the question because i dont want to force the user to download all the files.. – Dominicanstan Oct 28 '11 at 04:04