LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-25-2006, 04:32 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Question 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.
 
Old 05-26-2006, 09:27 AM   #2
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
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.
 
Old 05-26-2006, 09:28 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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.
 
Old 05-26-2006, 09:34 AM   #4
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
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

Last edited by zeitounator; 05-26-2006 at 10:17 AM.
 
Old 05-26-2006, 03:30 PM   #5
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
Thanks, guys! :-)
 
  


Reply

Tags
php


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php page can't display but download as php file? taiwf Linux - Software 2 03-07-2006 06:57 PM
Suse 9.3/apache2/php4 - Firefox tries to download index.php, other *php pages work stefanlasiewski Suse/Novell 1 01-18-2006 07:12 PM
download php namit Fedora 2 11-06-2005 08:21 PM
PHP Download Module essoft478 Programming 1 08-30-2005 11:31 AM
how can I change the apt-get download location? trees Linux - General 2 04-20-2004 01:54 AM


All times are GMT -5. The time now is 03:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration