How to create a ZIP file from multiple files in PHP ?

I would like to ask to suggest, how I can create compressed ZIP file with more files, by using PHP.
posted on 08.06.2019 at 19:36
0pnshow more
zeddzedd
Hi,

To create a ZIP file with more files, you can use the solution below. ZIP file multiple_files.zip will include image_1.jpg and image_2.jpg (renamed source files: file_1.jpg and file_2.jpg).

$zip = new ZipArchive();
$zipfilename = "multiple_files.zip";

if ($zip->open($zipfilename, ZipArchive::CREATE)===TRUE) {
$zip->addFile("file_1.jpg","image_1.jpg");
$zip->addFile("file_2.jpg","image_2.jpg");
$zip->close();
echo "ZIP file created";
}
else {
echo "Cannot open " . $zipfilename ;
}


You can add more files into ZIP archive by including another addFile functions in the source.
posted on 14.06.2019 at 13:31
0pnshow more
TimTim
share on facebookshare on twitter
2019 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.