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);
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′