Jump to content

File Output not retaining file extension.


pthurmond

Recommended Posts

I am working on creating an automatic CSV file output system for one of my admin pages and I have it most of the way there. The problem I am running into is that when the download comes up the file extension is no longer on the name, even though it is in the filename section of the header. So I get a file name with no extension on it. I just want to add the ".csv" part to the end. With the way it currently is I have to manually type the file extension in the dialog box. Below is a sample of my headers...

 

  //Outputs the CSV file as a page. Just call this and it will do the rest.
  function return_file($filename = 'Output')
  {
    header("Expires: 0");
    header("Cache-control: private");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Description: File Transfer");
    //header("Content-Type: application/vnd.ms-excel");
    //header("Content-type: text/plain");
    header("Content-type: text/x-csv");
    header("Content-disposition: attachment; filename=" . $filename . ".csv");
    
    echo $this->file;
    exit();
  }

 

As you can see I have tried several content types in the hopes that the change would solve the problem. However, it did not work. I am new to creating dynamic file downloads so I am probably missing something obvious.

 

Thanks,

Patrick

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.