protected function sendHeaders(string $filename)
    {
        if (strlen($filename) != strcspn($filename, '\\/')) {
            throw new Exception('The filename cannot contain the "/" and "\\" characters.');
        }

        $flag = FILTER_FLAG_STRIP_LOW;
        if (strlen($filename) !== mb_strlen($filename)) {
            $flag |= FILTER_FLAG_STRIP_HIGH;
        }

        $filenameFallback = str_replace('%', '', filter_var($filename, FILTER_SANITIZE_STRING, $flag));

        $disposition = sprintf('attachment; filename="%s"', str_replace('"', '\\"', $filenameFallback));
        if ($filename !== $filenameFallback) {
            $disposition .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
        }

        header('Content-Type: text/csv');
        header('Content-Transfer-Encoding: binary');
        header('Content-Description: File Transfer');
        header('Content-Disposition: '.$disposition);
    }
protected function sendHeaders(string $filename)
    {
        if (strlen($filename) != strcspn($filename, '\\/')) {
            throw new Exception('The filename cannot contain the "/" and "\\" characters.');
        }

        $flag = FILTER_FLAG_STRIP_LOW;
        if (strlen($filename) !== mb_strlen($filename)) {
            $flag |= FILTER_FLAG_STRIP_HIGH;
        }

        $filenameFallback = str_replace('%', '', filter_var($filename, FILTER_SANITIZE_STRING, $flag));

        $disposition = sprintf('attachment; filename="%s"', str_replace('"', '\\"', $filenameFallback));
        if ($filename !== $filenameFallback) {
            $disposition .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
        }

        header('Content-Type: text/csv');
        header('Content-Transfer-Encoding: binary');
        header('Content-Description: File Transfer');
        header('Content-Disposition: '.$disposition);
    }
protected function sendHeaders ( string $ filename ) { if ( strlen ( $ filename ) != strcspn ( $ filename , '\\/' ) ) { throw new Exception ( 'The filename cannot contain the "/" and "\\" characters.' ) ; } $ flag = FILTER_FLAG_STRIP_LOW ; if ( strlen ( $ filename ) !== mb_strlen ( $ filename ) ) { $ flag |= FILTER_FLAG_STRIP_HIGH ; } $ filenameFallback = str_replace ( '%' , '' , filter_var ( $ filename , FILTER_SANITIZE_STRING , $ flag ) ) ; $ disposition = sprintf ( 'attachment; filename="%s"' , str_replace ( '"' , '\\"' , $ filenameFallback ) ) ; if ( $ filename !== $ filenameFallback ) { $ disposition .= sprintf ( "; filename*=utf-8''%s" , rawurlencode ( $ filename ) ) ; } header ( 'Content-Type: text/csv' ) ; header ( 'Content-Transfer-Encoding: binary' ) ; header ( 'Content-Description: File Transfer' ) ; header ( 'Content-Disposition: ' . $ disposition ) ; }
Send the CSV headers.

Adapted from Symfony\Component\HttpFoundation\ResponseHeaderBag::makeDisposition

@throws Exception if the submitted header is invalid according to RFC 6266

@see https://tools.ietf.org/html/rfc6266#section-4.3
Send the CSV headers .