How to password protect zip in php?

2020-02-12 09:26发布

问题:

I am able to create zip file using ziparchive lib in php. Is there any way I can specify a password for the zip files that I create? Is there any other custom library that can do the same?

My php is running in safe mode and my hosting provider does not allow me to change it. So I'm not able to do shell_exec() function. Is there any other way around it by using any other library? I checked the DotNetZip Library, but it says it supports only .net based languages and in windows, nothing related with php is mentioned. Also I'm using a linux server.

The application is that I have a few xml files that are dynamically generated and need to be zipped and my clients will download it. But I need to put a password so that even though anyone intercepts it, they won't be able to open it.

Or is there any alternative way?

回答1:

shell_exec('zip -qjP <password> <archive> <file1> <file2> ... <file_n>');


回答2:

use this:

system('zip -P password zipfile.zip file.extension');

pass is the password, and file.extension will be zipped into zipfile.zip.

works on Windows and Linux