Join my Laravel for REST API's course on Udemy 👀

Create a Zip file using PHP

July 26, 2022  ‐ 1 min read

The archive extensions "Zip" allows you to create Zip archives with PHP. We can easily create Zip files by making use of the ZipArchive class.


$zip = new ZipArchive();

$zip->open('./', ZipArchive::CREATE);

// addFile('file path', 'file name in zip archive');
$zip->addFile('./', '');


After "opening" the Zip archive we can start adding files, at last we need to call the close method to properly save the changes.