There are some things to be considered in your code.
First, write those headers correctly. You will never see any server sending Content-type:application/pdf
, the header is Content-Type: application/pdf
, spaced, with capitalized first letters etc.
The file name in Content-Disposition
is the file name only, not the full path to it, and altrough I don't know if its mandatory or not, this name comes wrapped in "
not '
. Also, your last '
is missing.
Content-Disposition: inline
implies the file should be displayed, not downloaded. Use attachment
instead.
In addition, make the file extension in upper case to make it compatible with some mobile devices. (Update: Pretty sure only Blackberries had this problem, but the world moved on from those so this may be no longer a concern)
All that being said, your code should look more like this:
<?php
$filename = './pdf/jobs/pdffile.pdf';
$fileinfo = pathinfo($filename);
$sendname = $fileinfo['filename'] . '.' . strtoupper($fileinfo['extension']);
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"$sendname\"");
header('Content-Length: ' . filesize($filename));
readfile($filename);
Content-Length
is optional but is also important if you want the user to be able to keep track of the download progress and detect if the download was interrupted. But when using it you have to make sure you won't be send anything along with the file data. Make sure there is absolutely nothing before <?php
or after ?>
, not even an empty line.