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

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

问题描述

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

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,您可以执行类似的操作.请参阅 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 并看到您的 unzip 命令正在运行,他们可能会在该命令行上看到您的密码.

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天全站免登陆