0

I'm trying to convert a folder into zip using php i found code on the internet and try to use it and it did nothing? so my question is that is there nay extension to do this or library ?

$rootPath = realpath('E:\dir\sub_dir');

// Initialize archive object

// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$zip = new ZipArchive();
$zip->open('sub_dir.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);

$files = scandir($rootPath);
unset($files[0], $files[1]);
foreach ($files as $file) {
    $zip->addFile($dir.'\\'.$file);
}
$zip->close(); // enter code here
coudy.one
  • 1,382
  • 12
  • 24
Huzail Jamil
  • 96
  • 1
  • 1
  • 13

1 Answers1

0

Yes, you have to add/enable the PHP ZIP extension to properly open or write zip files. After installing this, do make sure that this extension is enabled at .ini.Hope this helps!

For more info, visit this link. A similar post is here. Do check this

Penguine
  • 519
  • 6
  • 19