Created
January 31, 2014 17:51
-
-
Save umidjons/8738580 to your computer and use it in GitHub Desktop.
Compress file with ZipArchive
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 | |
$file_name = 'myfolder/myfile.log'; | |
$info = pathinfo( $file_name ); | |
$zip = new ZipArchive(); | |
$zip_file_name = $info[ 'dirname' ] . DIRECTORY_SEPARATOR . $info[ 'filename' ] . '.zip'; | |
$zip_local_name = $info[ 'basename' ]; // file name in archive without directory | |
if ( true !== $zip->open( $zip_file_name, ZipArchive::CREATE ) ) | |
die( "Compressing failed!" ); | |
$zip->addFile( $file_name, $zip_local_name ); | |
$zip->close(); | |
// print link to download file: | |
echo '<a class="my-zip-file" href="<?= $zip_file_name; ?>">Compressed File</a>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment