By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,044 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,044 IT Pros & Developers. It's quick & easy.

Adding filename to downloaded file

P: n/a
Hi,

I'm using php to generate a csv file and want to force the user to
download it to their local PC.

Trouble is, when I use:

header("Content-Disposition: attachment; filename=\"download.csv\"");

the browser wants to save the file as download.csv.php

Any suggestions as to how I can get rid of the .php? I'd rather not tell
apache that it should pass csv files through php.

Thanks,

Russell.

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Russell <nu**@null.noemail> wrote in message news:<xk*****************@news-binary.blueyonder.co.uk>...
Hi,

I'm using php to generate a csv file and want to force the user to
download it to their local PC.

Trouble is, when I use:

header("Content-Disposition: attachment; filename=\"download.csv\"");

the browser wants to save the file as download.csv.php

Any suggestions as to how I can get rid of the .php? I'd rather not tell
apache that it should pass csv files through php.


IE needs specific headers. Always refer manual before posting any
questions http://in.php.net/header

<?php
$file_name = 'xx.csv';
header('Content-Type: text/comma-separated-values');
//IE need specific header...
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
{
header('Content-Disposition: inline; filename="'.$file_name.'"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
}
else
{
header('Content-Disposition: attachment;
filename="'.$file_name.'"');
header('Pragma: no-cache');
}
?>
---
"Dying is an art, like everything else"---Sylvia Plath
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2

P: n/a
R. Rajesh Jeba Anbiah wrote:
Russell [wrote]:
I'm using php to generate a csv file and want to force the user to [...]

There is no "force", despite what Skywalker'd have you believe.
header('Content-Type: text/comma-separated-values');


Perhaps the MIME media type text/x-comma-separated-values or perhaps
text/x-csv or perhaps something else prefixed with "x-"; there is no
text/comma-separated-values registered though.
Jul 17 '05 #3

P: n/a
Is the operation going to the PHP page in question a POST or a GET? I
have run into problems with IE before using a POST to launch a
download.

Try adding this line:

header("Content-type: application/octet-stream");

Also.

Russell <nu**@null.noemail> wrote in message news:<xk*****************@news-binary.blueyonder.co.uk>...
Hi,

I'm using php to generate a csv file and want to force the user to
download it to their local PC.

Trouble is, when I use:

header("Content-Disposition: attachment; filename=\"download.csv\"");

the browser wants to save the file as download.csv.php

Any suggestions as to how I can get rid of the .php? I'd rather not tell
apache that it should pass csv files through php.

Thanks,

Russell.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.