Created
October 1, 2010 02:35
-
-
Save bermi/605640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Input files to be included in the zip. Should perform sanity check on this | |
$files_to_package = array('catalog.pdf', '3dview.dwg'); | |
bring_files_locally_from_cloud_files_if_we_dont_have_a_local_cache_of_the_file($files_to_package); // nodoc :), @todo implement | |
// This file will be deleted once the PHP process ends | |
$zip_path = tmpfile(); | |
// Create zip file with all files on the base of the zip regardless of their path | |
exec("zip --junk-paths $zip_path ". join(" ", absolute_file_paths($files_to_package))); // @todo implement absolute_file_paths | |
// Sending headers | |
header("Pragma: public"); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
header("Cache-Control: public"); | |
header("Content-Type: application/zip"); | |
header("Content-Disposition: attachment; filename=Archive.zip"); | |
header("Content-Transfer-Encoding: binary"); | |
header('Content-Length: '.filesize($zip_path)); | |
// Send the buffer as soon as it is echoed | |
ob_implicit_flush(); | |
// Sends the file without taking all the ram | |
$buffer_size = 4096; | |
$fp = fopen($zip_path, "rb"); | |
while (!feof($fp)) { | |
echo fread($fp, $buffer_size); | |
} | |
// In case we don't trust on tmpfile effectiveness | |
unlink($zip_path); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment