2

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?

Rich
  • 107
  • 1
  • 13
  • I very much doubt that you can open a ZIP archive for writing using an HTTP URL. You want to use a file system path, not a URL. – 04FS Feb 03 '20 at 11:46
  • #04FS are you refering to my $zipname variable content? – Rich Feb 03 '20 at 11:50
  • 1
    Of course, what else. (Or are you saying, that your _“full path to the files”_ are also URLs? The `addFile` method also wants a local file as parameter, according to the manual. In that place URLs _might_ work, but it doesn’t mention any supported wrappers there as it usually does in such instances, if that was the case.) – 04FS Feb 03 '20 at 11:53
  • 1
    Thanks @04FS. I'm going to take a look at the manual. And yes, my variable are the full paths – Rich Feb 03 '20 at 13:44

0 Answers0