I’ve been trying to put together a page for our choir’s Members Only section to download multiple Training MP3s, using Checkboxes.
The files themselves are stored in a sub-directory of the main page, although for the sake of getting it working I could accept having them in the same directory instead, if necessary.
Please note: This is not my original coding, but something I found online. When placed in the Root Directory it works ok, but obviously that’s not where I need it to be.
The main site is based on a standard index.php format, located at the Site Root comprised of includes for Header, Body (of which this is one) & Footer.
I suspect the problem is something to do with the definition of the $file_folder.
I’ve added the echo “$file_folder”; line just to keep tabs on the value of $file_folder, which seems to look right.
The original defining value for $file_folder, based on running the page from the Site Root was $file_folder = “files/”; but because of the additional subdirectories, combined with having the page included in the root index.php, I’ve had to use an absolute address.
With my own extended address definition I’ve left the slash off the end, as if I leave it in, as demonstrated in the original script, the whole thing goes nuts, filling the browser with all sorts of garbage, slowing everything down & non responsive for ages before a refresh is possible. If left out, it displays, but simply doesn’t work.
The main script is placed at very top of page, before :
[php]
"; } foreach($post['files'] as $file){ $zip->addFile($file_folder.$file); // Adding files into zip } $zip->close(); if(file_exists($zip_name)){ // push to download the zip header('Content-type: application/zip'); header('Content-Disposition: attachment; filename="'.$zip_name.'"'); readfile($zip_name); // remove zip file is exists in temp path unlink($zip_name); } }else $error .= "* Please select file to zip
"; }else $error .= "* You dont have ZIP extension
"; ) ?>
[/php]
And the rest of the script within the tags.
[php]
<?php if(!empty($error)) { ?>
<?php echo $error; ?>
<?php } ?>
[/php]
And one of the checkbox input lines:
[php]
Summer 2014 - Ladies | |||
---|---|---|---|
Dance A Cachucha | All Parts | Both Sops | Both Altos |
…etc…
You will notice I’ve left the links in, as was the case in the original format of the page, and they still work fine.
The error message warning of no files selected works ok, so there’s nothing wrong with that side of things, but if a file is selected, then it just loops back to the beginning, clearing the selections.
Can anyone give any pointers as to what’s going wrong? Is it the definition of $file_folder (as I suspect), or is there something else I’m missing?
Thanks in advance for any help.