PHP Cli Create zip file with password – 7zip

0.29K views
no comments
18 May 2018 2:11 am

You cannot create zip file with password in php unless update php version from older to new atleast php 7.2. The following is best solution to create zipfile with password through 7zip or any other exe file with #cli command.
Create zip file with password in command line interface (CLI).
You will need to download 7zip file from 7-zip.org and the extract or install it, to get 7zip.exe and 7zip.dll both files are required for cli command.

Prepare 7zip Cli command in php

1 – define variable zip_exe_path set to absolute path of 7zip.exe file.
2 – define variable source path
3 – define variable password
4 – define variable output whre should be absolute path of zip file which will create

$zip_exe_path='D:/newxampp/htdocs/codetest/binary-files/7zip/7z.exe';
$source_path = 'D:/newxampp/htdocs/codetest/binary-files/7zip';
$password = 'TheZIPPassword__';
$resurive = ' -r ';
$output_path_n_name = 'D:/newxampp/htdocs/codetest/binary-files/7zip/zipfile.zip';
$cli_command = " $zip_exe_path a  $resurive  $output_path_n_name -p'$password' ";
shell_exec($cli_command);
create zip file in 7z with password-final result

create zip file in 7z with password-final result

result-enter-zip-password-to-open-file

result-enter-zip-password-to-open-file

Plain CLI code

D:/newxampp/htdocs/codetest/binary-files/7zip/7z.exe a -r D:/newxampp/htdocs/codetest/binary-files/7zip/7zip.zip D:/newxampp/htdocs/codetest/binary-files/7zip -p’123456′

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>