PHP

ADD FILES & FOLDERS WITH PHP ZIP ARCHIVE

(quick guide & examples)

CREATE ZIP FILE $z = new ZipArchive(); $z->open("demo.zip", ZipArchive::CREATE);

BASIC PHP ZIP ARCHIVE

01

ADD FILE & CREATE FROM STRING $z->addFile("file.txt", "name-in-zip.txt"); $z->addFromString("string.txt", "A string!");

ADD FOLDER $zip->addEmptyDir("folder"); 

CLOSE ZIP $zip->close();

OPEN ZIP FILE $z = new ZipArchive();  $z->open("demo.zip", ZipArchive::CREATE);

ADD FOLDER USING GLOB

02

ADD ALL IMAGES IN FOLDER $z->addGlob(   "FOLDER/*.{jpg,png,gif}", GLOB_BRACE, [   "add_path"=>"/", "remove_all_path"=>true ]); $zip->close();

OPEN ZIP FILE $z = new ZipArchive();  $z->open("demo.zip", ZipArchive::CREATE);

ADD FOLDER USING PATTERN

03

ADD ALL IMAGES IN FOLDER $z->addPattern(   "/\.(?:jpg|png)$/", "/FOLDER/", [   "add_path"=>"/", "remove_all_path"=>true ]); $zip->close()