I\'m zipping folders and files with php, but when I try to open up the zip file I get an cpgz file instead. After extracting that file I get another zip file. What it does i
I was just having exactly the same issue, and learned that these two function calls can help:
header("Content-disposition: attachment; filename=$filename");
header('Content-type: application/zip');
// Add these
ob_clean();
flush();
readfile($filename);
unlink($filename);
Usually setting Content-Disposition and Content-Length should be enough, however flushing PHPs output buffer and the underlying output buffer (Apache or such) helps when output is accidentally sent before headers are set in PHP.
In my case, commenting out the header() and readfile() calls for debugging helped to see, that warnings were output before the file was sent.
Hope that helps somebody in the future.