简体   繁体   English

PHP8 ZipArchive EM 常量 TRAD_PKWARE 不起作用

[英]PHP8 ZipArchive EM constant TRAD_PKWARE not working

i used ZipArchive::EM_TRAD_PKWARE, with password, but zip file is not encrypted.我使用了带有密码的 ZipArchive::EM_TRAD_PKWARE,但 zip 文件未加密。 I think that pkware not working.我认为 pkware 不工作。 Have solutions?有解决方案吗?

Thx谢谢

$zip->setEncryptionName('test.txt', ZipArchive::EM_TRAD_PKWARE, 'PASSWORD'); 

I got it working by the following example and rules:我通过以下示例和规则使其工作:

Two rules to make it work让它发挥作用的两条规则

I got inconsistent results when not following these 2 rules:不遵循这两条规则时,我得到了不一致的结果:

  1. Make sure the file to be encrypted contains data确保要加密的文件包含数据
  2. Make sure addFile is called before setEncryptionName确保在setEncryptionName之前调用addFile

Working example工作示例

test.txt测试.txt

Create the following test.txt file with the following content:使用以下内容创建以下 test.txt 文件:

test

test.php测试.php

Add the following PHP code to test.php:添加以下 PHP 代码进行测试。php:

$zip = new ZipArchive();
$zip->open("test.zip", ZipArchive::CREATE);
$zip->addFile("test.txt");
$zip->setEncryptionName('test.txt', ZipArchive::EM_TRAD_PKWARE, 'PASSWORD'); 
$zip->close();

Run test.php运行测试。php

php test.php

A zip file is now created which prompts for a password on unzip.现在创建了一个 zip 文件,它会在解压缩时提示输入密码。

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

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