CFile::send PHP Method

send() public method

Browser caching is prevented. This method works only for files.
public send ( null | string $fake_name = null, boolean $server_handled = False, null | string $content_type = null ) : boolean | null
$fake_name null | string New filename (e.g.: 'myfileFakedName.htm')
$server_handled boolean Whether file contents delivery is handled by server internals (cf. when file contents is read and sent by php). E.g.: lighttpd and Apache with mod-sendfile can use X-Senfile header to speed up file delivery blazingly. Note: If you want to serve big or even huge files you are definetly advised to turn this option on and setup your server software appropriately, if not to say that it is your only alternative :).
$content_type null | string Should be used to override content type on demand.
return boolean | null Returns bool or outputs file contents with headers.
    public function send($fake_name = null, $server_handled = False, $content_type = null)
    {
        if ($this->getIsFile()) {
            if ($this->getReadable() && !headers_sent()) {
                if ($content_type) {
                    $ctype = $content_type;
                } else {
                    $ctype = $this->getMimeType();
                    if (!$ctype) {
                        $ctype = 'application/octet-stream';
                    }
                }
                if ($fake_name) {
                    $filename = $fake_name;
                } else {
                    $filename = $this->getBasename();
                }
                // Disable browser caching.
                header('Cache-control: private');
                header('Pragma: private');
                header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
                header('Content-Type: ' . $ctype);
                header('Content-Transfer-Encoding: binary');
                header('Content-Length: ' . $this->getSize(False));
                header('Content-Disposition: attachment;filename="' . $filename . '"');
                if ($server_handled) {
                    header('X-Sendfile: ' . $this->_realpath);
                } else {
                    if ($contents = $this->getContents()) {
                        echo $contents;
                    }
                }
                exit;
            }
            $this->addLog('Unable to prepare file for download. Headers already sent or file doesn\'t not exist');
            return False;
        } else {
            $this->addLog('send() and download() methods are available only for files', 'warning');
            return False;
        }
    }