$zip = new ZipArchive();$code = $zip->open('myzip.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);if ($code === true) echo 'zip opened
';else echo $code.'
';$zip->addFile('somefile');$code = $zip->setPassword('secret');if ($code === true) echo 'password set
';else var_dump($code);$code = $zip->close();on the filesystem, the myzip.zip is created with somefile inside and $code is true but the zip file is not password protected ...
Reply content:
$zip = new ZipArchive();$code = $zip->open('myzip.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);if ($code === true) echo 'zip opened
';else echo $code.'
';$zip->addFile('somefile');$code = $zip->setPassword('secret');if ($code === true) echo 'password set
';else var_dump($code);$code = $zip->close();on the filesystem, the myzip.zip is created with somefile inside and $code is true but the zip file is not password protected ...
setPassword
A zip file without a password is not set up with a password. Instead, a password is set to decrypt it.
$zip = new ZipArchive();$code = $zip->open('myzip.zip');$zip->setPassword('123456');$zip->extractTo('/path');