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 ZipArchive实现多文件打包下载实例
-
php利用ZipArchive类操作文件的实例
-
php文件打包 下载之使用PHP自带的ZipArchive压缩文件并下载打包好的文件
-
php ZipArchive压缩函数详解实例
-
php使用ZipArchive函数实现文件的压缩与解压缩
-
php使用ZipArchive提示Fatal error: Class ZipArchive not found in的解决方法
-
php里array_work用法实例分析
-
php ZipArchive实现多文件打包下载实例
-
php的ZipArchive类用法实例
-
php文件打包 下载之使用PHP自带的ZipArchive压缩文件并下载打包好的文件_PHP教程