1

I'm packing files into the zip on serverside in PHP. In the output file there are additional directories and and after unpacking it into a folder I get subfolders with such a path leading to images: unpacked_folder/var/www/ji_bog/images/files*.jpg. How to move those files, to have files*.jpg directly in the zip? So I could get path like unpacked_folder/files*.jpg

doobeedoo
  • 11
  • 3
  • Found the answer in another question in another question https://stackoverflow.com/questions/5227774/remove-directory-structure-when-zipping-files-in-php?rq=1 – doobeedoo Jul 11 '17 at 11:27

1 Answers1

0

Try to get only images file from directory and add only selected images file into zip, So you will get only images file after unzip.

Not sure, hope so u want the same solution as per understanding ur question..

Try this if it works for you...

if (!is_dir($file)) {
    $file = basename($file);
    list($name, $ext) = explode('.', $file);
    switch ($ext) {
        case "png":
        case "gif":
        case "jpg":
            $zip->addFile(realpath($file), $file) or die ("ERROR: Could not add file: $file");
        break;
    }
}
Rahul Dhande
  • 483
  • 5
  • 9