How to Create a Zip File Using PHP?

by Dinesh 2014-06-15 19:11:42

Do you want to create a Zip file using Php. Use the simple given code to generate Zip file. ZipArchive is a pre-defined class which is is used to create a Zip file.
 
open($archive_file_name, ZIPARCHIVE::CREATE) !== TRUE) {
        exit("cannot open <$archive_file_name>
");
    }
  
    foreach ($file_names as $files) {
        $zip->addFile($file_path . $files, $files);
    }
    $zip->close();
  
    header("Content-type: application/zip");
    header("Content-Disposition: attachment; filename=$archive_file_name");
    header("Pragma: no-cache");
    header("Expires: 0");
    readfile("$archive_file_name");
    exit;
}$fileNames     = array('files/file1.docx',
    'files/file1.pdf');$zip_file_name = 'myFile.zip';

$file_path     = dirname(__FILE__) . '/';

zipFilesDownload($fileNames, $zip_file_name, $file_path);

?>
630
like
0
dislike
0
mail
flag

You must LOGIN to add comments