0

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();
}
Peter
  • 1,860
  • 2
  • 18
  • 47
  • First, confirm if the zip file is valid by downloading through a trusted binary method such as FTP. If invalid, fix the zipper, if valid, fix the downloaded. If the latter, run a binary diff between the manually downloaded zip and this version. Look for error messages or warnings in clear text specifically. – Chris Haas Jun 27 '22 at 01:01
  • @ChrisHaas I tried your guide and it happen to be during download that the file corrupt. Please any better way to download without issue? – Peter Jun 27 '22 at 09:10
  • Did you diff the two files and find an error or warning message? – Chris Haas Jun 27 '22 at 11:36

0 Answers0