Adding filename to downloaded file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Russell

    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=\"down load.csv\"");

    the browser wants to save the file as download.csv.ph p

    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.

  • R. Rajesh Jeba Anbiah

    #2
    Re: Adding filename to downloaded file

    Russell <null@null.noem ail> wrote in message news:<xkGwb.645 5$K%5.3715@news-binary.blueyond er.co.uk>...[color=blue]
    > 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=\"down load.csv\"");
    >
    > the browser wants to save the file as download.csv.ph p
    >
    > 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.[/color]

    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($_SERVE R['HTTP_USER_AGEN T'], 'MSIE'))
    {
    header('Content-Disposition: inline; filename="'.$fi le_name.'"');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    }
    else
    {
    header('Content-Disposition: attachment;
    filename="'.$fi le_name.'"');
    header('Pragma: no-cache');
    }
    ?>


    ---
    "Dying is an art, like everything else"---Sylvia Plath
    Email: rrjanbiah-at-Y!com

    Comment

    • John Dunlop

      #3
      Re: Adding filename to downloaded file

      R. Rajesh Jeba Anbiah wrote:
      [color=blue]
      > Russell [wrote]:
      >[color=green]
      > > I'm using php to generate a csv file and want to force the user to [...][/color][/color]

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

      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.

      Comment

      • Chung Leong

        #4
        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.noem ail> wrote in message news:<xkGwb.645 5$K%5.3715@news-binary.blueyond er.co.uk>...[color=blue]
        > 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=\"down load.csv\"");
        >
        > the browser wants to save the file as download.csv.ph p
        >
        > 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.[/color]

        Comment

        Working...