我是php和SO社区的新手。
我在:-Windows -Wamp
我最近的问题是制作一个受密码保护的zip以便下载。如您所知,Ziparchive不允许制作受密码保护的zip,而setpassword函数仅用于解密。
因此,我听说我可以通过命令行执行此操作,但是老实说,我exec()
在命令行中了解的唯一内容是php将执行zip.exe和密码保护文件。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
因此,请问在我的情况下(Windows / Wamp),使此“命令行”工作的步骤是什么?
这是我的脚本:
<?php
$ZipN='zip.zip';
$Zip = new ZipArchive();
//File path
$file_path=$_SERVER['DOCUMENT_ROOT'].'/PF/';
function zipFilesAndDownload($ZipN,$Zip,$file_path){
if ($Zip->open($ZipN, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$ZipN>\n");
}
$Zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");
$Zip->close();
//Password protect Not working !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
exec("zip -P password $file_path.$ZipN $ZipN");
//then send the headers to foce download the Zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$ZipN");
header("Content-length: " . filesize($ZipN));
header("Pragma: no-cache");
header("Expires: 0");
readfile("$ZipN");
// Delete the files from the server, even if the user cancels the download
ignore_user_abort(true);
unlink($file_path.$ZipN);
exit;
}
zipFilesAndDownload($ZipN,$Zip,$file_path);
?>
谢谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句