Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php ZipArchive setPassword is not work

php ZipArchive setPassword is not work

WBOY
WBOYasal
2016-08-20 09:04:172011semak imbas

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

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

if ($code === true)
    echo 'password set<br>';
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 ...
</code>

回复内容:

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

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

if ($code === true)
    echo 'password set<br>';
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 ...
</code>

setPassword不是把一个没有密码的ZIP文件设置有密码的. 而是设置一个密码用来解密的.

<code class="php">$zip = new ZipArchive();
$code = $zip->open('myzip.zip');
$zip->setPassword('123456');
$zip->extractTo('/path');</code>
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn