How do I add a generated excel file to a password protected zip and download it? I am using ZipArchive library. I am trying to add the excel file to zip but unfortunately zip is not getting generated.
if(isset($_POST["export_excel"]))
{
$sql = "SELECT * FROM Datas ORDER BY ID DESC";
$result = mysqli_query($connect, $sql);
....
....
....
$output .= '</table>';
$fileName = "DB".date('Y_m_d').".xls";
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$fileName");
echo $output;
$zip = new ZipArchive;
$tmp_file = 'myzip.zip';
if ($zip->open($tmp_file, ZipArchive::CREATE)) {
$zip->setPassword>addFile('PASSWORD', $fileName);
$zip->setEncryptionName($fileName, ZipArchive: header('Content-disposition:EM_AES_256 attachment; filename=files.zip');
header('Content-type: application/zip');
$zip->close();
readfile($tmp_file);
}
}