Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening and creating password protected zip files with PHP

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');
like image 350
Adrien Hingert Avatar asked Oct 10 '11 12:10

Adrien Hingert


2 Answers

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)
like image 65
Salvador Dali Avatar answered Sep 30 '22 14:09

Salvador Dali


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

like image 45
Aurelio De Rosa Avatar answered Sep 30 '22 13:09

Aurelio De Rosa