Displaying pdf file on a browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
HUNDU2
Forum Newbie
Posts: 2
Joined: Mon Oct 28, 2013 6:27 am

Displaying pdf file on a browser

Post by HUNDU2 »

Please i'm working on how display pdf file on a browser but each time i try i get this error.
This file can not be display correctly.
Please i your help.
Thanks in advanced


***** Please use PHP Code syntax tag *****

Code: Select all

<?php
mysql_connect("localhost", "root", "") or die ("Could not save image name Error: " . mysql_error());
mysql_select_db("pdf") or die("Could not select database");
$data = mysql_query("SELECT * FROM pdf2 where id='2'") or
die(mysql_error());
while($row = mysql_fetch_assoc( $data ))
{
$src=$row['path'];
$file ='http://localhost/pdf/images/';;
$filename =$src; 

header('Content-type: application/vnd.abode.xfdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);
}
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Displaying pdf file on a browser

Post by Christopher »

It is "adobe" not "abode". Try 'Content-type: application/vnd.adobe.xfdf'
(#10850)
HUNDU2
Forum Newbie
Posts: 2
Joined: Mon Oct 28, 2013 6:27 am

How to DISPLAY PDF FILE ON A BROWSER

Post by HUNDU2 »

Please i have been trying to display a pdf file on a browser, but it is not working. This is my code
I will be happy with any assistance.
Thanks in advanced.
this is my error message.
Adobe Reader could not open this file because it is either not a supported type or the file is damaged

<?php
mysql_connect("localhost", "root", "") or die ("Could not save image name Error: " . mysql_error());
mysql_select_db("pdf") or die("Could not select database");
$data = mysql_query("SELECT * FROM pdf2 where id='2'") or
die(mysql_error());
while($row = mysql_fetch_assoc( $data ))
{//Outputs the image and other data
$src=$row['path'];
$file ='http://localhost/pdf/images/';
$filename =$src; /* Note: Always use .pdf at the end. */

header('Content-type: application/vnd.adobe.xfdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);
}
?>
Last edited by requinix on Mon Oct 28, 2013 2:25 pm, edited 1 time in total.
Reason: merged from another thread
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to DISPLAY PDF FILE ON A BROWSER

Post by Christopher »

Try MIME type 'application/pdf'.
(#10850)
Post Reply