Opening and creating password protected zip files with PHP

家住魔仙堡 提交于 2019-11-30 03:48:49

问题


I have found the following two commands to respecively create and open password protected zip files. I was however wondering if it's possible to do this in pure PHP

echo system('zip -P password file.zip file.txt');  
echo shell_exec('unzip -P password file.zip');

回答1:


You can create simple file zip using some libraries (as PclZip) but you can't create zip with the password.




回答2:


It was not possible do do below PHP5.6.0. But in a new PHP5.6.x version developers added this functionality. So no need for a scary system or shell_exec (which can lead to security vulnerability).

So right now you can do something like this:

ZipArchive::setPassword($password)



回答3:


No, PHP's ZIP library has no support for passwords. You might look for another ZIP library that supports it and has PHP language bindings.

I don't know any from the top of my head that supports it for creating and opening.



来源:https://stackoverflow.com/questions/7712960/opening-and-creating-password-protected-zip-files-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!