php zip password,php ZipArchive setPassword is not work

$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

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值