Dena Dena - 3 months ago 16
PHP Question

generate document and then zip with php

I have an issue.
I have an index.php with several checkboxes.
Every checkbox represents a piece of code.
I am trying to create some generating tool.
For example: if I select four checkboxes, I want that four specific parts of code to generate in one php file, then zip it and download on my computer.

enter image description here

I know I can do it something like this:

$files = array('list.php', 'one-image.php', 'gallery.php', 'pdf.php');
$zipname = '';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));

but, at the moment i am pretty lost.
Thanks in advance.


Copied from comments:

Read the files yourself using file_get_contents, concatenate using +, write to zip with ZipArchive::addFromString.