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.

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 Like 28 Dislike
Previous forums Next forums
Other forums

Get last modified date of web page
Hai All,

In php how can i get last modified date of a give web page . I have tried to g

Can we convert non uni code system into unicode
Hi All,

Presently i am using non-unicode system and the sap version is 4.7.
Can i c

why preg_match_all does not return the number of matches
My regex looks like

X[^x{4e00}-x{9fa5}]*Y

(where X and Y are two Chinese characters)

count only commas outside parenteses
I have a sql table containing
id - query - query name
the first page contains a drop down men

Is there a function ... auto send IP
Is there some function that can be sent to a ddns service that returns the ip address of a ddns forw

newbie question
Hi out thereIm totaly new in this forum and to .net and vb so here is a totaly newbie question.I wan

I need to increse 6hours more, and i don't know how???
I need to increse 6hours more, and i don't know how???
<tr>
<t

post to self
Trying to get my form to submit to itself. However I am also trying to use an image for my submit bu

Log $_POST
How would i log submits on a form, by everyone? I want to then echo the number of submissions.

Getting Subdomain Name With PHP?
I want to grab the subdomain name with PHP so I can generate database queries.

for example my

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash