guys! I saw a lot of posts talking about using ZipArchive and how to get rid of the path structure inside the zip. So, here's my code:
$zipname = $post->post_title.".zip";
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach($gallery as $img) {
$attachment = get_attached_file($img['id']);
$zip->addFile($attachment, pathinfo($attachment,PATHINFO_BASENAME));
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
exit;
The problem is, that the zip file contains an image without path, f.e. /image.jpg and the same image in a multiple directories as it appears on the server /path/to/the/file/image.jpg.
So, I'm not sure why this is happening. Can somebody help on this?