homepage Welcome to WebmasterWorld Guest from 54.161.214.221
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Open/Save option on file
msthac01




msg:3585044
 3:09 pm on Feb 26, 2008 (gmt 0)

Another part of the project I'm working on is taking the embedded pdf file out of an xml reply I'm receiving and give the user an option to open/save the pdf file. Well the save option works correctly, but the open option does open Adobe, but then gives the error that the file can't be found. What could be the issue...here's the code I have so far:

<?php

//Display the previously created PDF file

$path = "CreditReports/".$PDFName;
//echo $path;
$fr = fopen($path, "rb");
$filedata = fread($fr, filesize($path));
fclose($fr);
//octet-stream
header ( "Content-Length: " . filesize ( $path ) );
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=".basename($path));
readfile($path);

?>

 

wtkad




msg:3585069
 3:22 pm on Feb 26, 2008 (gmt 0)

I had this problem with a .csv file and solved it by adding caching headers. I think IE doesn't keep it in the temporary files, since it's generated by php, so when it tries to open from there, it fails.

I added:

header("Expires: ".date("D, j M Y H:i:s",time()+(300))." UTC");
header("Cache-Control: Public");
header("Pragma: Public");

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