Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a couple things wrong First off ZIPARCHIVE::CREATE is not correct it should be ZipArchive::CREATE or ZipArchive::OVERWRITE (overwrite if your not deleting the zip file).</p> <p>Next your pathing is wrong. You are not telling readfile() the absolute path to the file. So you need to give absolute paths to the where the zip file is saved to and where it's read from.</p> <p>Also I find it unlikel that your root folder for the site is writable. So i moved the zip into the resumes folder for the code below. I tend to stay away from $_SERVER['DOCUMENT_ROOT'] my self and use the realpath() function.</p> <p>And lastly you have to make sure what ever folder the zip file is being created into that it has the 777 permissions on it.</p> <p>Here is the complete code change</p> <pre><code>&lt;?php /*foreach($_POST['files'] as $check) { echo $check;}*/ function zipFilesAndDownload($file_names,$archive_file_name,$file_path) { $zip = new ZipArchive(); //create the file and throw the error if unsuccessful if ($zip-&gt;open($file_path.$archive_file_name, ZipArchive::OVERWRITE )!==TRUE) { exit("cannot open &lt;$archive_file_name&gt;\n"); } //add each files of $file_name array to archive foreach($file_names as $files) { $zip-&gt;addFile($file_path.$files,$files); /*if(file_exists($file_path.$files)) //." ".$files."&lt;br&gt;"; echo "yes";*/ } $zip-&gt;close(); //then send the headers to foce download the zip file header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=$archive_file_name"); header("Pragma: no-cache"); header("Expires: 0"); readfile($file_path.$archive_file_name); exit; } //If you are passing the file names to thae array directly use the following method $file_names = array('test.txt'); //if you are getting the file name from database means use the following method //Include DB connection $archive_file_name='Resumes.zip'; $file_path=$_SERVER['DOCUMENT_ROOT']."/resumes/"; zipFilesAndDownload($file_names,$archive_file_name,$file_path); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload