Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the same problem but finally found a somewhat obscure solution and decided to share it here.</p> <p>I came accross the great <code>zip.lib.php</code>/<code>unzip.lib.php</code> scripts which come with <code>phpmyadmin</code> and are located in the "libraries" directory.</p> <p>Using <code>zip.lib.php</code> worked as a charm for me:</p> <pre><code>require_once(LIBS_DIR . 'zip.lib.php'); ... //create the zip $zip = new zipfile(); //add files to the zip, passing file contents, not actual files $zip-&gt;addFile($file_content, $file_name); ... //prepare the proper content type header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=my_archive.zip"); header("Content-Description: Files of an applicant"); //get the zip content and send it back to the browser echo $zip-&gt;file(); </code></pre> <p>This script allows downloading of a zip, without the need of having the files as real files or saving the zip itself as a file.</p> <p>It is a shame that this functionality is not part of a more generic PHP library.</p> <p>Here is a link to the <code>zip.lib.php</code> file from the phpmyadmin source: <a href="https://github.com/phpmyadmin/phpmyadmin/blob/RELEASE_4_5_5_1/libraries/zip.lib.php" rel="nofollow noreferrer"><a href="https://github.com/phpmyadmin/phpmyadmin/blob/RELEASE_4_5_5_1/libraries/zip.lib.php" rel="nofollow noreferrer">https://github.com/phpmyadmin/phpmyadmin/blob/RELEASE_4_5_5_1/libraries/zip.lib.php</a></a></p> <p><strong>UPDATE:</strong> Make sure you remove the following check from the beginning of zip.lib.php as otherwise the script just terminates:</p> <pre><code>if (! defined('PHPMYADMIN')) { exit; } </code></pre> <p><strong>UPDATE:</strong> This code is available on the CodeIgniter project as well: <a href="https://github.com/patricksavalle/CodeIgniter/blob/439ac3a87a448ae6c2cbae0890c9f672efcae32d/system/helpers/zip_helper.php" rel="nofollow noreferrer"><a href="https://github.com/patricksavalle/CodeIgniter/blob/439ac3a87a448ae6c2cbae0890c9f672efcae32d/system/helpers/zip_helper.php" rel="nofollow noreferrer">https://github.com/patricksavalle/CodeIgniter/blob/439ac3a87a448ae6c2cbae0890c9f672efcae32d/system/helpers/zip_helper.php</a></a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload