Thursday, August 14, 2008

How to open a PDF inside a php file - Restrict access to pdf files using php

Following code will show you how to open a pdf file inside a php file. This will allow you to restrict access to it. you can use some if else logic to control to display who see the pdf or who does not.


<?php

//you can get data from database in here
$user = 'some value';

if($user == 'some value')
{
$file = "test.pdf";
header('Content-type: application/pdf');
header("Content-Disposition: inline; filename=".$file);

//this line will make the file directly download
/* header("Content-Disposition: attachment; filename=".$file); */

header('Cache-control: private');
header('Expires: 0');
readfile($file);
}
else
{
echo 'you cannot access this file';
}
?>


Get Free Sinhala IT Learning Videos Kuppiya.com



Get custom programming done at GetAFreelancer.com!

No comments:

Post a Comment