csv file is shown instead of downloaded

I know there are many topics allready opened on this, however, I've tried everything without any success.

Here's my problem:

I've installed a plugin on opencart that is supposed to allow the admin to export the orders in XML, CSV, or Excel file. However, the browser opens the file instead of downloading it. The plugin works just fine on the demo page of the author. I asked the author if he had some clues for this problem, without any concrete answer. After trying a lot of possible solutions, I am starting to think that the problem may be caused by my server's settings.

The header looks like this :

$this->response->addHeader('Content-Type: application/vnd.ms-excel; charset=UTF-8');
$this->response->addHeader('Content-Disposition: attachment; filename="orders-' . date('YmdHis') . ".{$fext}\"");
$content = (($fext == 'csv') ? mb_convert_encoding($this->render(), 'GBK', 'UTF-8') :

I've tried changing the Content-Type for text/csv, application/csv, application/octet-stream, and some others. Nothing does the trick.

In my .htaccess file, I've tried adding this code:

AddType application/octet-stream .csv
AddType application/octet-stream .xls

And this one:

<FilesMatch "\.(?i:xls|csv)$">
 Header set Content-Disposition attachment

Without any success either.

Does someone have an idea?



After adding the headers, add this line below:


The output variable should contain the csv string data. You could also try:


Not sure how your order export tool creates the csv based on your description, but hope this shines some light on the issue.

Need Your Help

creating python lists on the fly and comparing them

python list python-2.7 set comparison

I need to open multiple files and compare the contents of them. The way I am doing in now is dirty. I want to know an elegant way of doing it. I need to open multiple files and see the common eleme...

How can I provide the field to use in a function?

c# .net lambda

Something working on the likes of Linq's OrderBy, in which you can specify the key with which it is supposed to do the ordering.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.