Tutorial :Download Form - Select files combile into Zip



Question:

Im looking to create a form where the user will select from a list of brochures. 10 in total.

They may only want to download 3 brochures, or 6, or 1, or 9, but the idea being they select what brochures they want and then a script combiles a zip file containg the required brochures.

Can anyone suggest anything?


Solution:1

PHP has a Zip extension for this UseCase

Example from the manual page for ZipArchive::addFile

$zip = new ZipArchive;  if ($zip->open('test.zip') === TRUE) {      $zip->addFile('/path/to/index.txt', 'newname.txt');      $zip->close();      echo 'ok';  } else {      echo 'failed';  }  

So, all you have to do is add the files the user selected to the ZipArchive and then send the Archive via header():

header('Content-type: application/zip');  header('Content-Disposition: attachment; filename="test.zip"');  readfile('test.zip');  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »