Home » PHP » Creating zip files using PHP

Creating zip files using PHP

How can I compress specific files or compress specific folder or compress bulk files using php.Only you want to add zip class and pass parameters as you want.
This class can be used to create archives of compress files in ZIP format.You can compressed archive to a file instead of a variable when the archive size exceeds a given memory usage threshold.
Also you can add comments to the zip file,rename final zip file,get Archive/zip files size.

Compress specific file

Download Compress specific file using PHP Example (33 KB)

Compress specific folder with it’s all files

Download Compress specific folder using PHP Example (2.35 MB)

Compress more files using PHP

Download Compress more files using PHP Example (1MB)

Tags

Similar posts

  • rohit patel

    how can zip only more then one selected folders with its file

    • read your files in the specific folder and get it’s names to the comma separated string.

      Method -1

      $fileNameStr = ”;

      foreach (glob(“myfolder/*.*”) as $filename) {
      $fileNameStr .= $filename . “,”; // adding comma
      }

      $fileNameStr = ‘file.pdf,image.jpg’;

      Method -2

      $fileNameStr = ”;
      $path = “myfolder/”;
      $files = scandir($path);
      foreach ($files as &$value) {
      $fileNameStr .= $value . “,”; // adding comma
      }

      Then follow the “Compress more files using PHP” section to do this.

      Regards