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