PHP

Creating zip files using PHP

  • 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