All “.php” files for example!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // create object $zip = new ZipArchive(); // Open archive if ($zip->open('newZipArchive.zip', ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } // Add all .php files in directory to archive foreach (glob ('*.php') as $file) { $zip->addFile(realpath($file)) or die ("Could not add file: $file"); } // Close and save archive $zip->close(); echo "Archive created successfully."; |
