Reputation: 13
This is my code:
$file = 'test.jpg';
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
test.jpg is a file on my system. I can open it and nothing is wrong with it. The download gets started but when i try to open the downloaded image, it says that it cant be opened. Im testing it on Chrome. Does someone have a solution? Thanks a lot.
Edit: the downloaded .jpg is only 23kb where as the file i want is 135kb.
Upvotes: 1
Views: 1528
Reputation: 667
Try to set header
header('Content-Type: image/jpeg');
ob_clean();
exit;
Upvotes: 1