Am trying to secure files with password before downloading it, but it showing error.
Am using PhpZip
Password Secure Archive
$zipFile = new \PhpZip\ZipFile();
$zipFile->addFile(__DIR__ . "/../files/oneTextFile.txt");
// Or $zipFile->addFile(__DIR__ . "/../files/oneZipFile.zip");
$zipFile->setPassword("12345Abc");
$zipFile->saveAsFile("secure-file.zip");
$zipFile->close();
Download Code
$file = __DIR__ . "/downloads/secure-file.zip";
if(file_exists($file)){
$type = mime_content_type($file);
if(!empty($type)){
header("Content-Type: {$type}");
}else{
header('Content-Type: application/octet-stream');
}
//header('Content-Type: package/x-generic');
header('Content-Description: File Transfer');
header("Cache-Control: private");
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Connection: Keep-Alive');
header('Pragma: public');
header('Content-Disposition: attachment; filename="'.$name.'"');
header("Content-Length: " . filesize($file));
readfile($file);
unlink($file);
exit();
}