Page 1 of 1
How to create password protected zip files using PHP?
Posted: Tue Aug 12, 2008 11:45 pm
by rasana
Hi All,
How to convert files(i.e. txt, video files, .doc ect) into password protected .zip format on wamp/xamp server?
Re: How to create password protected zip files using PHP?
Posted: Wed Aug 13, 2008 7:35 am
by lukewilkins
Assuming you are running Linux you can do this in your php:
Code: Select all
$last_line = system('zip -P yourpassword newfile.zip tobezipped.php', $retval);
echo 'Last line of the output: ' . $last_line . '<br/>';
echo 'Return value: ' . $retval . '<br/>';
But please note that this is potentially insecure as Linux may be set up on a multi-user system which can allow other users to see the commands you have ran, and therefore see the password that you set in the command line. This may be really insecure if you are on a shared host and your host has not taken this in to account.
Using -e instead of -P will prompt for your password (and therefore it is not shown to anyone else) but this may not be feasible if you are wanting to run this on the fly in a file (unless you had some sort of expect, but I'm not sure I could help you there).
Hope that helps, and let me know if you have any problems with it.
Luke
Re: How to create password protected zip files using PHP?
Posted: Thu Aug 14, 2008 1:55 am
by rasana
Thanks for replying
but i'm working on windows.
Re: How to create password protected zip files using PHP?
Posted: Thu Aug 14, 2008 7:54 am
by lukewilkins
Ah, I see.
I'd recommend this then.
http://www.onfocus.com/2007/01/3900
It is a Perl script that is able to handle zipping on a Windows system. Just set-up, pass it a filename and [poof!] you have a zipped file of the same name + .zip
As mentioned in the comments on that page, cygwin is a pretty cool piece of software. I have only played with it a bit, but it basically allows you to run your windows system like it is Linux (Linux commands and all!). I'm sure there is a way to use that and be able to run the first line of code inside the system() function.
Hope that helps!
Luke