I have no idea if this is possible since there is no information available on the internet. I spend two hours searching without any result.
I am trying to zip a directory without knowing the file names that are in the directory. I tried many methods but they include the whole path, I only want the files in the zip.
I have tried the following:
$zipFile = "./testZip.zip";
$zipArchive = new ZipArchive();
if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE))
die("Failed to create archive\n");
$zipArchive->addGlob("./*.txt");
if (!$zipArchive->status == ZIPARCHIVE::ER_OK)
echo "Failed to write files to zip\n";
$zipArchive->close();
and:
$zip = new ZipArchive;
$zip->open('myzip.zip', ZipArchive::CREATE);
foreach (glob("target_folder/*") as $file) {
$zip->addFile($file);
if ($file != 'target_folder/important.txt') unlink($file);
}
$zip->close();