-   Programming (
-   -   php: is it possible to change the name of a download? (

eantoranz 05-25-2006 04:32 PM

php: is it possible to change the name of a download?
I'm working on downloading the attachments of mails (working with IMAP).

I want to know if it's possible to set the name of the file the person will download? I know the Content-type can be set with a header so the web agent knows what type of file is being downloaded... however, is there a way I can tell the agent the file name? I didn't find an http header to do it on rfc2616.

Spudley 05-26-2006 09:27 AM

You're right, I'm not sure it can be done in the http headers. I'd typically use mod-rewrite to achieve that sort of thing.

acid_kewpie 05-26-2006 09:28 AM

i have an asp script which includes

Response.AddHeader "Content-Disposition","attachment; filename=Blah blah blah.csv"
so i'd assume the Content-Disposition header would work jstu as well when php generated.

zeitounator 05-26-2006 09:34 AM

The good source is always the documentation.... Extracted from


Originally Posted by php documentation
If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

// 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

For the exact rfc, chapter 15.5 of rfc2616 ("Content-Disposition Issues") refers to rfc2183

eantoranz 05-26-2006 03:30 PM

Thanks, guys! :-)

All times are GMT -5. The time now is 08:15 PM.