LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   php: is it possible to change the name of a download? (http://www.linuxquestions.org/questions/programming-9/php-is-it-possible-to-change-the-name-of-a-download-448537/)

eantoranz 05-25-2006 03: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 08: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 08:28 AM

i have an asp script which includes
Code:

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 08:34 AM

The good source is always the documentation.... Extracted from http://php.net/manual/en/function.header.php

Quote:

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.
Code:

<?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');
?>


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

eantoranz 05-26-2006 02:30 PM

Thanks, guys! :-)


All times are GMT -5. The time now is 09:47 PM.