php ZipArchive setPassword is not work

查看:73
本文介绍了php ZipArchive setPassword is not work的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

$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 ...

解决方案

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

$zip = new ZipArchive();
$code = $zip->open('myzip.zip');
$zip->setPassword('123456');
$zip->extractTo('/path');

这篇关于php ZipArchive setPassword is not work的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆