Help: problem with Headers to download PDF file
Posted on
16th Feb 2014 07:03 pm by
admin
Hi,
I'm trying to implement a script where when a user clicks a link he gets a PDF file to open or save.
Did you know?Explore Trending and Topic pages for more stories like this.
In my index.php page I have the following link:
Code: <a href="http://localhost/example/get_file.php">Click here to get the file</a>
And the script is in get_file.php:
Code: <?php
$path = '/docs/document.pdf';
$mm_type="application/pdf";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " . filesize($path) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary");
readfile($path);
exit();
?>
Unfortunately it's not working properly. When clicking on the link and either selecting 'open' or 'save' from the dialog box, the end result is always the same; the end file is about 1KB in size when originally it was 456KB and therefore it's damaged.
Any ideas on why this is happening?
Thanks!
No comments posted yet
Your Answer:
Login to answer
243
28
Other forums
Email to a friend script problems
I have this send-to-a-friend script with 2 issues:
1) When you open the form popup on a p
I think i'm using the syntax incorrectly
Hi Everyone!
I'm new to this forum and a newbie with PHP - I'm glad I found this site - I hop
PHP loop
Okay so I have several "articles" stored in a mysql database and am attempting to echo tho
Preloading images
Posting this question here because I am not sure where this should belong.I am building an asp.net a
How to secure my login data to my database?
Hi there,
It may be a stupid question but I don't know how to secure my login data to my data
A Few Questions
Hi, I want to ask a few questions that I can't seem to find..
1) I'm creating a "shortcu
Cache PHP Objects/Classes?
Does anyone have ideas about caching PHP objects using something like: http://memcached.org/
JSON SORT WITH PHP
I have two products that I want to sort by say "Id:17, value: xxx" using php
The page w
Google Map
I have done Google Map Integration for one my project. But for that we need the "latitude and l
how do i make new line after *
First check this page here. and you see my report. Im pulling form a mysql db. I want to beable to m