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

Switch letters in message (basic cryptology)...
I am trying to switch letters around in a message for an application on my site (see here). The prob

Track downloads' status
Hello,

I need to make somehow, some system, to track whether downloads are completed or faile

Deleting pointers froms vector?
Hi. I have a vector filled with pointers and I want to delete the pointers. I could do a loop and do

Alternate messaging
I have 4 strings in MySQL db1

$string1 : Hello
$string2 : Hi
$string3 : Great
$strin

Help with PHP Calendar code...
Hello, I'm new to this forum and I'm glad I found it.
I wrote this code for a PHP calendar as an

Get to know your fellow coder
I think it's time we got personal around here. There's a lot of code swapping and a few members kno

xApp Analytics in BI 7.0
Dear all,

I am trying to implement xApp Analytics in BI 7.0. After I installed the analyt

Blank record injected into database
I always found several blank records inside my database, although $SESSION is required to insert the

recrawling
Can anyone suggest me how may i know a page is updated before it is being downloaded, so that i can

frame help
on the bottom frame is menu.html

Code: <body><form action='link.php' met

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