如何仅使用PHP提取具有密码的ZIP文件? [英] How to extract a ZIP file that has a password using only PHP?

查看:146
本文介绍了如何仅使用PHP提取具有密码的ZIP文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里只看到一个问题,但没有回答我的问题.我正在运行一台典型的LAMP服务器,该服务器在Redhat Linux上具有最新的PHP 5和MYSQL 5.

I have seen only one question on here but it does not answer my question. I am running a typical LAMP server that has the most up to date PHP 5 and MYSQL 5 with Redhat Linux.

我需要找到一个仅PHP的解决方案,因为主机不允许我使用shell.

I need to find a PHP only solution because my host does not allow me to use shell.

这是我的代码,用于提取未从vBulletin上传到另一个目录的密码的ZIP:

Here is my code that extracts ZIPs that are not passworded from vBulletin uploads to another directory:

if ($_GET['add'] == TRUE){
$zip = new ZipArchive;
 $res = $zip->open($SOURCE FOLDER);
 if ($res === TRUE) {
     $zip->extractTo('$DESTINATION FOLDER/');
     $zip->close();
     echo 'File has been added to the library successfuly';
     //Add a flag to that file to indicate it has already been added to the library.
     mysql_query("UPDATE attachment SET library = 1 WHERE filedataid='$fileid'");    
 } else {
     echo 'A uncompression or file error has occured';
 }}

肯定有某种方法可以仅使用PHP来完成此操作!谢谢.

There must be some way to do this using just PHP, surely! Thank you.

更新:我的主机通知我服务器上安装了gzip,但7-Zip没有安装.我也在研究shell访问.

UPDATE: My host informs me that gzip is installed on the server but not 7-Zip. I am looking into shell access too.

推荐答案

脚本可使用7zip可执行文件,然后调用它以通过system()使用密码解压缩文件.

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);

如果主机已安装unzip,则可以执行与unzip类似的操作.参见 http://linux.about.com/od/commands/l/blcmdl1_unzip .htm .

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

它支持带密码的-P,所以类似这样:

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

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

注意:如果有人在系统上执行ps命令,则可以在该命令行中看到您的密码,并且看到您的解压缩命令正在运行.

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

这篇关于如何仅使用PHP提取具有密码的ZIP文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆