My website contains a section that allows users to access restricted PDF files if they have access to them. Basically, they arrive at a page which has a nav bar at the top, allowing them to cycle between PDF files. Below this, there is an iframe which is linked to a PHP page that does the retrieval of the file, and displays it. This file is called falr_pdf.php, and depending on how it is accessed, the PDF file is either displayed inline, or downloaded as an attachment.
Here is the navbar page, along with the falr_pdf.php IFRAME embedded, to give you a clear idea.
As you can see, the PDF should be displayed inline, and then if the user clicks "Download File", the same page is opened in a new tab, but to download the file as an attachment instead of displaying it inline.
My problem is that this works flawlessly for small PDF files, but anything larger than about 1.6MB will take an incredibly long time to display inline. However, if they are downloaded using the direct link instead, they download at normal speed, very quickly. Here is the code I am using...
$path = $falr_filesbasedir . "/" . $folder . "_pdf/" . $file . ".pdf";
$public_name = basename($path);
header('Content-Length:'.filesize($path));
header('Content-type: application/pdf');
header('Content-Disposition: ' . $method . '; filename="' . $public_name . '"');
readfile($path);
exit;
Now I know that the issue is not in any of my variables or links, since it works fine for every type of small file, and the download works fine for large files. It's only that large files don't display inline correctly.
$method
is only ever "inline"
or "attachment"
Is this a bug with readfile()
? Or is it something to do with my PHP settings?
I am at a complete loss here.