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
28
Other forums
tag inside php... hi
Code: <?php echo "<td width="$columnWidth%" align=&Exporting new records Trying to figure out the best way to set this up.
People register my site.
Their prof Alterar a hora do servidor Se alguém souber, ajude-me a adicionar 6 horas, obrigado <tr> & $_POST variable un-useable I'm trying to use a $_POST variable in a mysql update statement but i can't use it for some unknown ereg_replace issue hi there people
i have this code happening with regards to my wamp server. is this something mail with attachment problems Hi. I have the following code: Code: else if(file_exists("site".$timp.".zip") PHP & Java Hello,
can PHP code be used inside java code?
Code: [Select]<SCRIPT LANGUAGE=&q Opening Multiple Files/Links in Order. I want to open links in order/one-by-one and check each for a specific string.
Example: I Phase Error I can't seem to find :(` Hey guys, I can seem to find my phase error on this. I am getting this error
[error] Pars gmmktime or mktime I live in the UK, i am within the GMT (with daylight saving time ie 1 hour difrence between summer a
|