How to extract a ZIP file that has a password using only PHP?

别来无恙 提交于 2019-11-29 11:20:42

Have 7zip executable available to the script and call it to uncompress the file with the password via system().

$strCommandLine = "7z e fileToUnzip.7z -pTHEPASSWORD";
system($strCommandLine);

You can do something similar with unzip, if you host has that installed. See http://linux.about.com/od/commands/l/blcmdl1_unzip.htm.

It supports -P with a password, so something like this:

$strCommandLine = "unzip fileToUnzip.7z -P THEPASSWORD";
system($strCommandLine);

Caveat: someone could see your password on that command line if they do a ps on the system and see your unzip command running.

you can use this function setPassword ( string $password ) http://php.net/manual/en/ziparchive.setpassword.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!