简体   繁体   English

zip文件的密码保护不起作用

[英]password protection for a zip file is not working

 My php version : 5.4.6  

This is my code. 这是我的代码。 After excecuting this i got an erroe 执行完之后,我得到了一个错误

   $zip = new ZipArchive();
   $code = $zip->open('zipfiles/test.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
   if ($code === true)
    echo 'zip opened<br>';
   else
    echo $code.'<br>';
   $zip->addFile('test.jpg');

   $code = $zip->setPassword('secret');

   if ($code === true)
     echo 'password set<br>';
   else
     echo $code.'<br>';

   $code = $zip->close();
   if ($code === true)
    echo 'closed<br>';
   else
    echo $code.'<br>';

   echo 'done<br>';

But i got an error that 但是我有一个错误

   Fatal error: Call to undefined method ZipArchive::setPassword() in D:\xampp\htdocs\zipfile.php on line 25

Documentation says you need php 5.6.0 or higher. 文档说您需要php 5.6.0或更高版本。 You have 5.4.6. 您有5.4.6。 So you need to upgrade your php install. 因此,您需要升级php安装。

You can find the function setPassword() at the bottom of the list of new functions added in PHP 5.6 . 您可以在PHP 5.6中添加的新函数列表的底部找到函数setPassword()。

"setPassword" does not work in this case. 在这种情况下,“ setPassword”不起作用。 This function only sets the password to be used to decompress the archive; 此功能仅设置用于解压缩存档的密码; it does not turn a non-password-protected ZipArchive into a password-protected ZipArchive. 它不会将不受密码保护的ZipArchive转换为受密码保护的ZipArchive。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM