4

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?

Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57
hablema
  • 540
  • 1
  • 5
  • 17
  • Create an encrypted zip archive with PHP - http://stackoverflow.com/questions/646195/create-an-encrypted-zip-archive-with-php – Malitta N Mar 04 '12 at 16:18
  • I think this is going to be tricky, as the zipping is probably performed in native code, and you seem to be stuck with using PHP only code, or am I missing something here? – Maarten Bodewes Mar 04 '12 at 17:29

2 Answers2

4
shell_exec('zip -qjP <password> <archive> <file1> <file2> ... <file_n>');
dotoree
  • 2,983
  • 1
  • 24
  • 29
  • 1
    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 languages and in windows, nothing related with php is mentioned. Also i'm using a linux server. – hablema Mar 04 '12 at 17:08
  • @hablema please update your question with the information provided in your comment – Maarten Bodewes Mar 04 '12 at 17:27
0

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

Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57