28, May 2012

Open/Save option on file - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Open/Save option on file
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: Open/Save option on file  (Read 1258 times)
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« on: Feb 26, 2008, 04:04:48 pm »

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);

?>
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Feb 26, 2008, 10:12:29 pm »

I suppose if you will work with absolute paths it could be much better (especially when you are running scripts in CLI mode)

For instance this :

$path "CreditReports/".$PDFName;?>

should become this:

$path dirname(__FILE__) . "/CreditReports/".$PDFName;?>

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« Reply #2 on: Feb 26, 2008, 10:52:46 pm »

I still get the same behavior with adding the dirname(__FILE__) . to the path, the save option still works and the open option still says "file can't be found."
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #3 on: Feb 26, 2008, 10:59:30 pm »

That is not possible. Have you echoed the filename to see if it is correct?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« Reply #4 on: Feb 26, 2008, 11:12:19 pm »

here's the echo of $filename looks like its an issue with the slashes...I cut out the first part of the path but it is correct...

...\public\Enterprise/CreditReports/BarnDiane.pdf
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #5 on: Feb 26, 2008, 11:31:09 pm »

Slashes should not be an issue. I guess you are on a windows server, so case should not be an issue too.

Looks like a very strange problem....

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« Reply #6 on: Feb 26, 2008, 11:37:04 pm »

yes this all resides on a w2k3 server running php 4.4.4, and yes its very strange...the really weird part is that at one point the mbstring.dll was enabled in the .ini file and while that was the case both options worked fine.  but issues began to arise after the mbstring.dll was uncommented in the .ini file so we had to comment it back out, and since that change I've been unable to get the open option to work again.  Makes no sense to me, but then again I've only been coding php for about 6 months.
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #7 on: Feb 26, 2008, 11:41:08 pm »

I am coding php for years and I am sure this code is ok. If you haven't done anything wrong (like giving a false filename or a path that does not exist) I guess it can be some kind of issue with w2k server (I use linux and apache)

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Sandwich Artist
*
Posts: 25
186 credits
Members referred : 0


« Reply #8 on: Feb 26, 2008, 11:41:37 pm »

I just received this response to my thread on another forum.....

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");

Adding those headers in worked, now Open and Save options both work.  Hope this helps anyone else that comes across the same issue...Thanks for everyones help trying to figure this out.
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #9 on: Feb 26, 2008, 11:43:38 pm »

Headers have nothing to do with the file system though Smiley

Anyway, good to know that it finally worked Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7613
Tags : php open/save readfile() Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Open/Save option on file
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 09:53:50 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.