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
Merger of 6 sister companies under one flagship company after go live
Dear Experts,
I need one help regarding Merger of sister companies of same group. currently we
phpmailer class & pop.gmail.com?
Code: <?php
$mail->IsSMTP();
$mail->Host = "pop.gmail.com";
why this query can delete duplicates ?
why this query can delete duplicates ? Anybody can give me the detailed explanation ?
Tha
Is there a quick way to do this?
Hi all,
I need to create a mysql table from php that goes a little something like this
Upload file!
Ok i have a form..
Code: <form name="form1" method="post" action=&quo
Displaying image from database
Hi,
I've got a site where that's got a database behind it. Currently it has loads of items in
Small problem with image resize script
Hi!
I am a little bit new to php and I have an issue installing an image resize script I down
big pagination problem in php
<?php
$connect = mysql_connect("localhost", "root", "")
getting weird error..
okay, I'm getting an error on this particular function, something about the syntax in the mysql LIMI
Help with php code
Hello, can anyone tell me why this php word trap fails to work,
and the trigger words get blow r