Hi All,
How to convert files(i.e. txt, video files, .doc ect) into password protected .zip format on wamp/xamp server?
How to create password protected zip files using PHP?
Moderator: General Moderators
- lukewilkins
- Forum Commoner
- Posts: 55
- Joined: Tue Aug 12, 2008 2:42 pm
Re: How to create password protected zip files using PHP?
Assuming you are running Linux you can do this in your php:
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
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/>';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?
Thanks for replying
but i'm working on windows.
but i'm working on windows.
- lukewilkins
- Forum Commoner
- Posts: 55
- Joined: Tue Aug 12, 2008 2:42 pm
Re: How to create password protected zip files using PHP?
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
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