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
Need help adding a timestamp to my filename/variable
Hello,
I'm kind of stupid when it comes to php and I need a tiny bit of help. I've got a f
Locking mysql tables with php
Hi
BACKGROUND:
I have multiple instances of the same php script running in a WAMP environ
upload image name with extension using php
hi frds..
<input id="file1" type="file" name="file[]" &a
Warning message
I've put a website that I was doing live and I'm getting this warning message when I try to add a ne
Data type mismatch
Hi,
I am migrating data from algol to c.I mapped real datatype in algol to double datatype in
Edit MySQL Row Using PHP and HTML Form
Hello,
Here's what I'm trying to do. Build a page where a user enters a MySQL row number in.
Sessions work for me and not others?
I'm having a bit of bad luck with sessions. In the past they have worked fine for me, but this time
Java API in PHP?
I have an application that we use internally here at the office.
The software company provide
How to use Substr
I want to check for the word CATEGORY: inside a string which can be CATEGORY: ITEM
and remove the
ASP.NET Validation Event Cycle
Hi,
I have asp button as follow: