homepage Welcome to WebmasterWorld Guest from 54.237.249.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Open a pdf file from php link
msthac01




msg:3569018
 9:55 pm on Feb 7, 2008 (gmt 0)

I have just toiled for a few days on receiving an xml file through http post and then removing the embedded cdata tag and processing the data to create a pdf file. I have managed to create the file, but am unsure on how to get it to open in adobe acrobat from a php link. Basically when the user clicks a button data is sent to retrieve the clients credit report, the data is returned in an xml file with the embedded pdf within the file. My question is that when the user clicks the button and everything is done processing how can I get the newly created pdf file to open in adobe for the user to view? I tried a hyperlink starting with <a href="file://filelocation> but it tries to first open the file in internet explorer then gives the error that the version of adobe we are using can't display pdfs in the browser (which is a lie because it works in another application we use) but then after you click ok, adobe opens up the file. How can I skip the middle portion where IE tries to open the file?

 

PHP_Chimp




msg:3569937
 7:20 pm on Feb 8, 2008 (gmt 0)

If the mime type of the page is application/pdf then the browser should ask whatever program is set to open pdf's to open the link.
However you may find that some browsers can display pdf natively, so these will not open another program.

Assuming the pdf is using a .pdf extension then the mime type should be picked up from that. However if you are serving this as xml then the mime type will not be application/pdf.
You could always try forcing a download.
There are a load of scripts on this forum and the web that will help with force download.

Do you need to have the pdf embedded in xml? Or could you serve it directly?

msthac01




msg:3570062
 9:38 pm on Feb 8, 2008 (gmt 0)

I'm actually pulling the pdf out of an xml file from an http post response. i have went the route of trying to force a download so the user can download or open in adobe, the issue is that when you click open it says it can't find the file, but you can save it and everything works fine. Whats weird is that it was working until I had to change a config parameter in my php.ini file to turn off the mbstring.dll, because it was causing issues in other areas of my web app(though I don't know why). Ever since I turned that off the "open" option doesn't work when the dialog pops up. Here's the code I have so far:
[php]
$file = $PDFName;
$path = "CreditReports/".$PDFName;
$fr = fopen($path, 'r');
$filedata = fread($fr, filesize($path));
fclose($fr);

header ( 'Content-Length: ' . filesize ( $path ) );
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=$file");
readfile($path);
[php]

This was the original code that was working in whole until the config change, since then I've tried subbing /pdf in the content-type: statement but no change in the end result. I echoed out $path and its the correct place where the pdf file is created after pulling the data out of the xml file. Any idea on what would keep this code from working after that config change?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved