I'm trying to grab a PDF file from a directory above the docroot and have it display as would be expected. I do not want the user to download the file, per se. Rather, I want it to be displayed in their browser.
Here's my code thusfar...
mysql_connect("localhost","segue") or die(mysql_error());
mysql_select_db("seguelogic") or die(mysql_error());
$invID = $_GET['id'];
$clientid = $_SESSION['userinfo']['userid'];
$q = "SELECT * FROM invoices WHERE timestamp=\"$invID\" AND clientid=\"$clientid\"";
$r = mysql_query($q) or die(mysql_error());
if($row = mysql_fetch_assoc($r)){
$pdfFile = "/home/httpd/seguelogic/invoices/".$row['filename'];
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/pdf");
header( "Content-Disposition: attachment; filename=".basename($file));
header( "Content-Description: File Transfer");
@readfile($pdfFile);
}
else
echo "error";
As it stands, I get a download prompt with what is obviously a temporary file name.
UPDATE:
I've gotten it to download and launch Acrobat Reader outside fo the browser. I still wanna launch it within the browser.
RESOLVED:
I played with the headers a bit and got it sorted out. Here's my final code for those interested in downloading files from above the docroot:
<?
mysql_connect("localhost","segue") or die(mysql_error());
mysql_select_db("seguelogic") or die(mysql_error());
$invID = $_GET['id'];
$clientid = $_SESSION['userinfo']['userid'];
$q = "SELECT * FROM invoices WHERE timestamp=\"$invID\" AND clientid=\"$clientid\"";
$r = mysql_query($q) or die(mysql_error());
if($row = mysql_fetch_assoc($r)){
$pdfFile = "/home/httpd/seguelogic/invoices/".$row['filename'];
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/pdf");
header("Content-Description: File Transfer");
@readfile($pdfFile);
}
else
echo "error";
?>
Enjoy..