zip -P 命令无法创建密码保护 zip 文件 [英] zip -P command not working to create password protect zip file

查看:62
本文介绍了zip -P 命令无法创建密码保护 zip 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我制作了一个脚本,用于创建特定目录的 zip 文件,然后从工作正常的目录中删除除 zip 之外的所有文件.

First i made a script for creating a zip file of the particular directory and then remove all files except zip from the directory that working fine.

但现在我在脚本中实现了 zip -P 密码命令,使其受密码保护,但不起作用,

But now i implemented the zip -P password command into the script to make it password protected that is not working,

当我在下载后尝试解压缩文件时,它在不询问任何密码的情况下解压缩.请让我正确告诉我我在做什么错.

When i tried to extract the file after downloading it is extracting without asking any password. Please make me correct to tell me whats wrong i am doing.

这就是我尝试这样做的方式:

this is how i tried to do that:

exec('cd ' . escapeshellarg($directory_location) . ' ; zip -r ' .escapeshellarg($directory_location).'/'.escapeshellarg($zipname) . ' * ; '.$command.' '.escapeshellarg($zipname).' chmod 777 '.escapeshellarg($zipname).'; find . -type f -not -name \''.escapeshellarg($zipname).'\' -exec rm \{\} \; ' );

这是输出:

cd '/home/example/public_html/downloads/9c1f97ab931b9f4dc461c164f119a340/20' ; zip -r '/home/example/public_html/downloads/9c1f97ab931b9f4dc461c164f119a340/20'/'Xm18u_download.zip' * ; zip -P 'testPassword' '/home/example/public_html/downloads/9c1f97ab931b9f4dc461c164f119a340/20'/'Xm18u_download.zip' 'Xm18u_download.zip' ; 'Xm18u_download.zip' chmod 777 'Xm18u_download.zip'; find . -type f -not -name ''Xm18u_download.zip'' -exec rm \{\} \;

已关闭(找到解决方案)

推荐答案

我得到了解决方案,这是使用递归模式创建 zip 文件:

I got the solution, this is working with recursive mode zip file creation:

zip -r -P <password> 

对我来说是:

$command = '-P '.escapeshellarg($password);
exec('cd ' . escapeshellarg($directory_location) . ' ; zip -r '.$command.' ' .escapeshellarg($directory_location).'/'.escapeshellarg($zipname) . ' * ; '.escapeshellarg($zipname).' chmod 777 '.escapeshellarg($zipname).'; find . -type f -not -name \''.escapeshellarg($zipname).'\' -exec rm \{\} \; ' );

希望这对其他人有帮助;)

Hope this is helpful for someone else ;)

这篇关于zip -P 命令无法创建密码保护 zip 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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