I have a download link on my website from where we can download attachments. The pdf file is downloading perfectly but the images, docs and zip file are downloading as corrupt.
Below is the code which I am using for download. The code is working fine in my local pc but not on the server.
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($FilePath));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($FilePath));
readfile($FilePath);
exit;
The corruption occurs if your php script echoes anything before your headers.
Try using the same code, but in a separate php script.
Try adding
header('Content-Transfer-Encoding: binary');