navtarainc
asked on
Read PDF file from outside of public_html folder
Hi all,
I am facing a problem with the read the PDF file outside of public_html folder i.e
/home/rakesh/ramteke/abc.p df
can anybody suggest how many ways to do it using php script. I tried it by readfile() function but it damage the pdf file by putting %PDF to the beging of the file. and acrobat anable to open this file.
Thanks in advance
I am facing a problem with the read the PDF file outside of public_html folder i.e
/home/rakesh/ramteke/abc.p
can anybody suggest how many ways to do it using php script. I tried it by readfile() function but it damage the pdf file by putting %PDF to the beging of the file. and acrobat anable to open this file.
Thanks in advance
moreover the HTTPD user would not have read rights within a user's home directory.
@walkerke readfile is binary save and preseves binary data.. SO readfile is one option to output file conetent to the http stream.
Other option would be to use fpassthru like
$name = '/home/rakesh/ramteke/abc. pdf';
$fp = fopen($name, 'rb');
// dump the picture and stop the script
fpassthru($fp);
Other option would be to use fpassthru like
$name = '/home/rakesh/ramteke/abc.
$fp = fopen($name, 'rb');
// dump the picture and stop the script
fpassthru($fp);
I stand corrected.
ASKER
Thanks for your suggestions but problem was different one
i.e
if /home/rakesh/ramteke/……/ab c.pdf is the path for the pdf file
$pathname =$_GET['reportname'];
$filename="/home/updev/dms _reports/Q uotingTool /bin/".$pa thname;
file_exists($filename)or die("No File available");
header("Content-Type: application/pdf");
$fp = fopen($filename, 'rb');
fpassthru($fp);
Now, I changed the way i.e
$ filename =$_GET['reportname'];
file_exists($filename)or die("No File available");
header("Content-Type: application/pdf");
$fp = fopen($filename, 'rb');
fpassthru($fp);
and it works
Thanks again for u r help
i.e
if /home/rakesh/ramteke/……/ab
$pathname =$_GET['reportname'];
$filename="/home/updev/dms
file_exists($filename)or die("No File available");
header("Content-Type: application/pdf");
$fp = fopen($filename, 'rb');
fpassthru($fp);
Now, I changed the way i.e
$ filename =$_GET['reportname'];
file_exists($filename)or die("No File available");
header("Content-Type: application/pdf");
$fp = fopen($filename, 'rb');
fpassthru($fp);
and it works
Thanks again for u r help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you intend to do with the PDF codes once you've read them with the readfile()? Reading a PDF using readfile() will read the ASCII codes within PDF file. If you wish to serve the PDF file to the HTML stream, this is not the correct method.