I'm creating a zip file through php around 2-3mbs and at the end i want to send that zip file to the user for download.
Unfortunately using the below does not work for some reason. Well it works but not as it was supposed to. The file gets to the browser as it should. I download it, open it but when i try to exract or view the files inside it breaks down saying it's corrupted. If however i go and open the file that exists in the directory zip file opens fine and i can exract-view everything there. Any ideas why is this happening?
if (headers_sent()) {
echo 'HTTP header already sent';
} else {
if (!is_file($zip_name)) {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
echo 'File not found';
} else if (!is_readable($zip_name)) {
header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
echo 'File not readable';
} else {
header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Length: ".filesize($zip_name));
header("Content-Disposition: attachment; filename=\"".$zip_name."\"");
readfile($zip_name);
}
}
$zip_name
? – Expectant