-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Labels
Description
Description
The following code:
<?php
$zip = new ZipArchive();
if ($zip->open('/tmp/test1.zip', ZipArchive::CREATE) === TRUE) {
$zip->setPassword('secret_');
$zip->addFile('/tmp/test.txt', 'test.txt');
$zip->setEncryptionName('/tmp/test.txt', ZipArchive::EM_AES_256);
$zip->close();
}
Resulted in this output:
I am able to extract the content without the password.
But I expected this output instead:
that I need to use the password during the extraction.
Working but not optimal
If I leave entryname
empty in addFile()
method then I need to type the password before I want to extract the content but then the tmp
appears inside the zip file as a directory structure.
<?php
$zip = new ZipArchive();
if ($zip->open('/tmp/test2.zip', ZipArchive::CREATE) === TRUE) {
$zip->setPassword('secret_');
$zip->addFile('/tmp/test.txt');
$zip->setEncryptionName('/tmp/test.txt', ZipArchive::EM_AES_256);
$zip->close();
}
PHP Version
PHP 8.1.8
Operating System
Ubuntu 20.04.4 LTS