I am using this PHP script to download a file:
$status=stripos($_SERVER['HTTP_REFERER'],'servername');
if($status===false)
{
header('Location:http://xyz.com);
}
else
{
header('Content-disposition: attachment; filename=XXX.pdf');
header('Content-type: application/pdf');
readfile('http://www.xyz.com/Downloads/XXX.pdf);
}
However when I download the file in any browser it says it is corrupt.
Please Help!
But this code works fine
header("Content-type: application/pdf");
header('Content-Disposition: attachment; filename="sample.pdf"');
readfile('/var/www/sample.pdf');
Please change filename=XXX.pdf to filename="XXX.pdf" and check.
Oh sorry!! You should provide a base path or relative pat to the content mean it should be like readfile('/var/www/Downloads/XXX.pdf);
rather readfile('http://www.xyz.com/Downloads/XXX.pdf);
Thanks