欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php ZipArchive setPassword is not work

程序员文章站 2022-04-18 15:12:46
...
$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 ...

回复内容:

$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不是把一个没有密码的ZIP文件设置有密码的. 而是设置一个密码用来解密的.

$zip = new ZipArchive();
$code = $zip->open('myzip.zip');
$zip->setPassword('123456');
$zip->extractTo('/path');
相关标签: php