When exporting Orders from the grid view in magento, as CSV, the name of the file downloaded is appended with -, attachment. This seems at the minute to be only happening in Chrome.

I've looked at where this download is triggered in Mage_Core_Controller_Varien_Action;

protected function _prepareDownloadResponse(
    $contentType = 'application/octet-stream',
    $contentLength = null)
    $session = Mage::getSingleton('admin/session');
    if ($session->isFirstPageAfterLogin()) {
        return $this;

    $isFile = false;
    $file   = null;
    if (is_array($content)) {
        if (!isset($content['type']) || !isset($content['value'])) {
            return $this;
        if ($content['type'] == 'filename') {
            $isFile         = true;
            $file           = $content['value'];
            $contentLength  = filesize($file);

        ->setHeader('Pragma', 'public', true)
        ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
        ->setHeader('Content-type', $contentType, true)
        ->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength)
        ->setHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"')
        ->setHeader('Last-Modified', date('r'));

    if (!is_null($content)) {
        if ($isFile) {

            $ioAdapter = new Varien_Io_File();
            $ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
            $ioAdapter->streamOpen($file, 'r');
            while ($buffer = $ioAdapter->streamRead()) {
                print $buffer;
            if (!empty($content['rm'])) {
        } else {
    return $this;

Playing about with this file a little, if I remove attachment; from the line ->setHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"') then the filename becomes orders.csv-, filename=-orders.csv.

It seems to be that Chrome isn't using the headers correctly, but can anyone shed any light on what can be done to solve this?


After being referred to the following SO question;


...adding the semicolon as so fixes the issue.

            ->setHeader('Content-Disposition', 'attachment; filename="'.$fileName.'";')

However editing this file is not a permanent solution. I've tested the issue in and the download works fine. Examining the same line, its apparent that they've fixed the issue by adding the true parameter to replace the existing header;

            ->setHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"', true)

In the meantime though, what's the best way to circumvent the issue on I'm not going to edit the core file, and I don't really want to overwrite that abstract class either.

  • What is the filename you use? Does it contain a ; or some other chars which breaks the process? A quote "? Commented Jul 22, 2015 at 9:58
  • The filename is just set, or at least should be set, as orders.csv. The user has no control over what the file name is, as its hardcoded in the exportCsvAction function in the Mage_Adminhtml_Sales_OrderController class.
    – thebluefox
    Commented Jul 22, 2015 at 10:00

1 Answer 1


The best way to fix this is to implement this method in your own controller. If you have more than one this sucks, but think about an upgrade.

There are a lot of bugs and SECURITY ISSUES which are fixed in later versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.