How to extract a ZIP file that has a password using only PHP?(如何仅使用 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 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何仅使用 PHP 提取具有密码的 ZIP 文件?
				
        
 
            
        基础教程推荐
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - php中的PDF导出 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				