0

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();
Quartermain
  • 163
  • 3
  • 17
  • 1
    Welcome to Stack Overflow! This question is a little short on information. Can you share what you have tried (code), and the exact problems you have run into? – Jay Blanchard Apr 08 '15 at 14:08
  • possible duplicate of [ZipArchives stores absolute paths](http://stackoverflow.com/questions/12902387/ziparchives-stores-absolute-paths) - ([This one](http://stackoverflow.com/questions/3993105/php-creating-zips-without-path-to-files-inside-the-zip) might also be informative.) – showdev Apr 09 '15 at 22:40

0 Answers0