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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|