Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emojiijome/81200195d8a26e9ffcf8 to your computer and use it in GitHub Desktop.
Save emojiijome/81200195d8a26e9ffcf8 to your computer and use it in GitHub Desktop.
<?php
if (isset ( $_GET ['fetchAll'] ) && ! empty ( $_GET ['fetchAll'] )) {
//$file is like a container,tempnam is very interesting
$file = tempnam ( "tmp", "zip" );
$zip = new ZipArchive ();
$zip->open ( $file, ZipArchive::OVERWRITE );
$fileDir = dirname ( __FILE__ ) . "/../../download_files/";
//slice '.'& '.'
$xlses = array_slice ( scandir ( $fileDir ), 2 );
foreach ( $xlses as $xls ) {
$zip->addFile ( $fileDir . $xls, $xls );
}
$zip->close ();
header ( 'Content-Type: application/zip' );
header ( 'Content-Length: ' . filesize ( $file ) );
header ( 'Content-Disposition: attachment; filename="file.zip"' );
readfile ( $file );
unlink ( $file );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment