kartik\grid\controllers\ExportController::setHttpHeaders PHP Method

setHttpHeaders() protected method

Sets the HTTP headers needed by file download action.
protected setHttpHeaders ( string $type, string $name, string $mime, string $encoding = 'utf-8' ) : void
$type string the file type
$name string the file name
$mime string the mime time for the file
$encoding string the encoding for the file content
return void
    protected function setHttpHeaders($type, $name, $mime, $encoding = 'utf-8')
    {
        Yii::$app->response->format = Response::FORMAT_RAW;
        if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") == false) {
            header("Cache-Control: no-cache");
            header("Pragma: no-cache");
        } else {
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Pragma: public");
        }
        header("Expires: Sat, 26 Jul 1979 05:00:00 GMT");
        header("Content-Encoding: {$encoding}");
        header("Content-Type: {$mime}; charset={$encoding}");
        header("Content-Disposition: attachment; filename={$name}.{$type}");
        header("Cache-Control: max-age=0");
    }