Save file as attachment

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I talked about this some time ago somewhere else, now I am working
with this again...

I want to offer the user to save/open a file, instead of the browser
opening it by itself (as e.g. a jpeg picture would).
Looking into the advices I got at the time, I came up with this:

$filename=ExtractFileName($file); // my own function included here

header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");

It works, I get the dialog, but the white window remain.

What options do I have of closing the window, so I only have the
My email at has that option, some odd link (/attn/hex-code-
here ) which behaves as I'd like mine too.

What would people around here do?


Re: Save file as attachment

If the link that sends the user to the page with your PHP code on it
has the target as a new window (i.e <a href="download.php"
target="_blank">) then the new window will open and you will see the
dialog box in front of a empty window (i.e the white you are seeing).

If you make the link stay within the same browser window (i.e <a
href="download.php"> with no target) then it should just open the
dialog box with the current browser window in the background.

It is because you are not sending new HTML for the current browser
window so it has no information for updating so it stays the same.

I think that is what you were looking for but if not then please
clarify a little more.


Re: Save file as attachment

Quoted text here. Click to load it

No need to. Seems like you understood it the way it is. I'll test that
later today.


Re: Save file as attachment

Quoted text here. Click to load it

And it worked. Tnanks&BR

Site Timeline