I have files that are already located on my server. I have created an array that has the full path to the files. The file names resolve correctly.
$files = array($sm_image1ok, $sm_image2ok, $sm_image3ok, $sm_ambianceok, $sm_planok, $sm_mobilierok, $sm_rapportok);
I have a classical upload path for wordpress:
$zipname = 'https://www.siteurl.com/wp-content/uploads/wpfile'.$post->ID.'.zip';
I have tried to create the zip file with the following code
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
}
echo "Number of files : " . $zip->numFiles . "\n";
echo "Status :" . $zip->status . "\n";
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
And this is my download link:
<a href="'.$zipname.'">Download files.</a>
My Number of files and my Status are indicating "0". When I click on the link it opens a page with no results (unknown page). I was hoping for the popup zip download modal window and not a new page. The zip file is not being created on the server. I am the site administrator so I do have write permissions. My "uploads" folder has permissions set at 705. Can someone point me in the right direction please?