Christopher Shaw
Password Zip File In Php
Posted on Friday 07th June 2019 in Code

In PHP you can open and read ZIP archives, including ones with passwors through the use of ZipArchive, but there are scenarios where you may want to create an archive and add a password. This is not currently supported by ZipArchive but can be achieved by using a cli command executed by php.


  • PHP
  • Linux / Unix based host
  • zip command


    $fileName = "myfile.txt";
    $zipName = ""
    $password = 'mypassword';
    system("zip -P $password $zipName $fileName");