public function download($file = null, array $downloadOptions = array())
    {
        $o = $downloadOptions + $this->downloadOption;

        if (!is_file($file)) {
            throw new \RuntimeException('File not found', 404);
        }

        $name = $o['filename'] ? : basename($file);
        $name = rawurlencode($name);

        // For IE
        $userAgent = $this->request->getServer('HTTP_USER_AGENT');
        if (preg_match('/MSIE ([\w.]+)/', $userAgent)) {
            $filename = '=' . $name;
        } else {
            $filename = "*=UTF-8''" . $name;
        }

        $this->setHeader(array(
            'Content-Description' => 'File Transfer',
            'Content-Type' => $o['type'],
            'Content-Disposition' => $o['disposition'] . ';filename' . $filename,
            'Content-Transfer-Encoding' => 'binary',
            'Expires' => '0',
            'Cache-Control' => 'must-revalidate',
            'Pragma' => 'public',
            'Content-Length' => filesize($file),
        ));

        // Send headers
        $this->send();

        // Send file content
        readfile($file);

        return $this;
    }
public function download($file = null, array $downloadOptions = array())
    {
        $o = $downloadOptions + $this->downloadOption;

        if (!is_file($file)) {
            throw new \RuntimeException('File not found', 404);
        }

        $name = $o['filename'] ? : basename($file);
        $name = rawurlencode($name);

        // For IE
        $userAgent = $this->request->getServer('HTTP_USER_AGENT');
        if (preg_match('/MSIE ([\w.]+)/', $userAgent)) {
            $filename = '=' . $name;
        } else {
            $filename = "*=UTF-8''" . $name;
        }

        $this->setHeader(array(
            'Content-Description' => 'File Transfer',
            'Content-Type' => $o['type'],
            'Content-Disposition' => $o['disposition'] . ';filename' . $filename,
            'Content-Transfer-Encoding' => 'binary',
            'Expires' => '0',
            'Cache-Control' => 'must-revalidate',
            'Pragma' => 'public',
            'Content-Length' => filesize($file),
        ));

        // Send headers
        $this->send();

        // Send file content
        readfile($file);

        return $this;
    }
public function download ( $ file = null , array $ downloadOptions = array ( ) ) { $ o = $ downloadOptions + $ this -> downloadOption ; if ( ! is_file ( $ file ) ) { throw new \ RuntimeException ( 'File not found' , 404 ) ; } $ name = $ o [ 'filename' ] ? : basename ( $ file ) ; $ name = rawurlencode ( $ name ) ; // For IE $ userAgent = $ this -> request -> getServer ( 'HTTP_USER_AGENT' ) ; if ( preg_match ( '/MSIE ([\w.]+)/' , $ userAgent ) ) { $ filename = '=' . $ name ; } else { $ filename = "*=UTF-8''" . $ name ; } $ this -> setHeader ( array ( 'Content-Description' => 'File Transfer' , 'Content-Type' => $ o [ 'type' ] , 'Content-Disposition' => $ o [ 'disposition' ] . ';filename' . $ filename , 'Content-Transfer-Encoding' => 'binary' , 'Expires' => '0' , 'Cache-Control' => 'must-revalidate' , 'Pragma' => 'public' , 'Content-Length' => filesize ( $ file ) , ) ) ; // Send headers $ this -> send ( ) ; // Send file content readfile ( $ file ) ; return $ this ; }
Send file download response

@param string $file The path of file
@param array $downloadOptions The download options
@return $this
@throws \RuntimeException When file not found
Send file download response