I have PHP v7.3 and I'm running the following PHP code, trying to create a password protected ZIP-file.
The ZIP-file is created, but it's not password protected. What could be wrong?
$zip = new ZipArchive();
$zipFile = $this->backupDir . '/' . $db_file_name . '_' . $this->backupFormat . '.sql.zip ';
if (file_exists($zipFile)) { unlink($zipFile); }
$zip->open($zipFile, ZipArchive::CREATE);
$password = 'top-secret';
$zip->setPassword($password);
$fileName = $this->backupDir . '/' . $db_file_name . '.sql';
$baseName = basename($fileName);
$zip->addFile($fileName, $baseName);
$zip->setEncryptionName($fileName, ZipArchive::EM_AES_256);
$zip->close();
I'm not getting any errors. It's just that he generated ZIP-file is unprotected.
When checking out phpinfo
, you see libzip version is used. This must be increased to version 1.2.0 or newer.