Adding filename to downloaded file

This is a discussion on Adding filename to downloaded file within the PHP Language forums, part of the PHP Programming Forums category; Hi, I'm using php to generate a csv file and want to force the user to download it to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-25-2003
Russell
 
Posts: n/a
Default Adding filename to downloaded file

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.

Reply With Quote
  #2 (permalink)  
Old 11-25-2003
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: Adding filename to downloaded file

Russell <null@null.noemail> wrote in message news:<xkGwb.6455$K%5.3715@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
Reply With Quote
  #3 (permalink)  
Old 11-26-2003
John Dunlop
 
Posts: n/a
Default Re: Adding filename to downloaded file

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.
Reply With Quote
  #4 (permalink)  
Old 11-27-2003
Chung Leong
 
Posts: n/a
Default Re: Adding filename to downloaded file

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 <null@null.noemail> wrote in message news:<xkGwb.6455$K%5.3715@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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:32 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0