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
Print out contents of to Excel
I have got this script that gathers all the data that I need but I need it to send it to excel inste
Help with simple query
Hi,
I'm trying to do a Query with a Union where I want to print the number of rows $tc conta
Display Database
I need to create a shopping cart. I found this code online: http://conceptlogic.com/jcart/
Unfort
Fetching META TAGS through
Hello everybody
I want to fetch meta tags of a domain.
It will be done from following code of
Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.
Some code runs as perfectly valid code,
PHP - MySQL Fail
My PHP code will only execute the first part of my code...
Code: <?php
sessio
filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h
Reg Ex
Im trying to search for the string: srv_9 (Dead ???)
I thought to use preg_match, however I d
Logging and nologging bulk insert
Hi,
oracle version: 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
script is pulling more then they have....
I have this script for my game where they can change there race. This will cost them 2,500 points. H