Hello to everyone, I'm new to this group, and I've been facing a
problem I couldn't solve, I don't know how to serch for it in the
list's old messages, so I'll tell you what it is and see if you can
help me.
I have this lines:
if (isset($_GET['download']) && ($_GET['download'] >= 1)) {
if ($_GET['download'] == 1)
header('Content-type: application/doc');
else if ($_GET['download'] == 2)
header('Content-type: application/rtf');
else if ($_GET['download'] == 3)
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . $_GET['file']
. '"');
readfile($_GET['file']);
}
It should show to the user an dialog to the user, so he can choose to
save the file or to open it directly.
The dialog shows and the user chooses, and here comes the problem, by
using the 'Content-type', 'Content-Disposition' and 'readfile' the
content of the page I'm in is "attached" to the end of the file I'm
downloading. When it's an DOC or RTF file, the content of the page
doesn't affect the funcioning, but if it's an PDF the string taht goes
"attached" in the end of the file happens to make the file useless.
All I want to do is to use some routine to let the user choose to save
the file or to read it directly, nothing more, nothing less.
I have been trying to solve this problem for at least some weeks, and
I couldn't find some information that could really help me.
BTW, at php.net I found the following example:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
I used (as can be seem) this example with some modifications, but not
too much, and it happens that it's useless for my needs, if someone
knows how to fiz it or some other way to do what I want please let me
know, I'll be very grateful.
Thanx in advance.
morten.