Tags
PHP , zip
Asked 7 years ago
26 Apr 2017
Views 1987
pratik

pratik posted

how to make zip file in PHP ?

how to make zip file in PHP ?
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00


The ZipArchive class A file archive, compressed with Zip.


$files = array('1.jpeg','2.txt','3.wav');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();
Rasi

Rasi
answered Nov 30 '-1 00:00

Use linux command to make zip file
command is
zip -r filename


// Make Zip name
$zipname = "one.zip";
// Make a zip file
$cmd = `zip -r $zipname *`;
exec($cmd);

use exec to execute command.
Post Answer