I have headers which force a file download, rather than viewing it in the browser but I need to give that option. I've looked at several posts on Stack Overflow which answer this question (eg How to force files to open in browser instead of download (pdf)?) but I am still not getting the desired result, so I wanted to check if I'm missing something.
Here are my headers to force a download
$file = 'file.pdf';
$filePath = 'path/to/file.pdf';
header("Cache-Control: public");
header("Content-Length: 20000");
header("Content-Description: File Transfer");
header("Content-Type:file");
header('Content-Disposition: attachment; filename="$file"');
header("Content-Transfer-Encoding: binary");
readfile($filePath);
And here are the header to try and display the file in the browser
header("Cache-Control: public");
header("Content-Length: 20000");
header("Content-Description: File Transfer");
header("Content-Type:file");
header('Content-Disposition:inline; filename="$file"');
header("Content-Transfer-Encoding: binary");
readfile($filePath);
So the only change is the content-disposition header.
However, I am still just being shown the markup in the browser (see image).
Any ideas?
Many thanks