I am making a website where users can upload, read and download pdf files. The upload is working well, they can read the pdf file online and can also download it using the adobe reader plugin. But the download code I wrote is giving me a hard time. It downloads the file but the file doesn't open in the adobe reader. It gives an error "Adobe Reader could not open file because it is either not a supported file type or because the file has been damaged".
Here is my code:
if(is_file($fullPath)) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts['extension']);
switch($ext) {
case 'pdf':
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . $fullPath. '"');
break;
default:
header('Content-type: application/octet-stream');
}
header('Content-length: $fsize');
header('Cache-control: private'); //use this to open files directly
readfile($name);
}
exit;
could some one help me out with it?