douni9620 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 :

<?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>
");
    }
$Zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.
");
$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);
?>

Thanks

  • 写回答

1条回答 默认 最新

  • doutuan8887 2015-09-15 01:31
    关注

    7-zip has an amazing command-line based zip utility that supports passwords (-p switch). Get it here (get the Extra version for the standalone commandline). Here are some examples of its command-line usage.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)