2015-09-15 01:25
浏览 41

命令行zip(wamp / windows / php)

I'm new to php and S.O community.

I'm on : -Windows -Wamp

My problem recently is to make a password protected zip for download. As you know, Ziparchive doesn't allow to make password protected zip, function setpassword is just for decryption.

So I heard I could do that by command line, but to be honest all I understand about exec() in command line is that php will execute zip.exe and password protect file.

So please what's the steps for making this "command line" work in my case (windows/wamp) ?

Here is my script :

$Zip = new ZipArchive();
//File path

function zipFilesAndDownload($ZipN,$Zip,$file_path){
    if ($Zip->open($ZipN, ZIPARCHIVE::CREATE )!==TRUE) {
        exit("cannot open <$ZipN>
$Zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.

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

    // Delete the files from the server, even if the user cancels the download




  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题