X-Sendfile is a feature allowing a web application to redirect the request for a file to the webserver
that in turn processes the request, this way eliminating the need to perform tasks like reading the file
and sending it to the user. When dealing with a lot of files (or very big files) this can lead to a great
increase in performance as the web application is allowed to terminate earlier while the webserver is
handling the request.
The request is sent to the server through a special non-standard HTTP-header.
When the web server encounters the presence of such header it will discard all output and send the file
specified by that header using web server internals including all optimizations like caching-headers.
As this header directive is non-standard different directives exists for different web servers applications:
- Apache:
X-Sendfile
- Lighttpd v1.4:
X-LIGHTTPD-send-file
- Lighttpd v1.5:
X-Sendfile
- Nginx:
X-Accel-Redirect
- Cherokee:
X-Sendfile and X-Accel-Redirect
So for this method to work the X-SENDFILE option/module should be enabled by the web server and
a proper xHeader should be sent.
**Note**
This option allows to download files that are not under web folders, and even files that are otherwise protected
(deny from all) like
.htaccess.
**Side effects**
If this option is disabled by the web server, when this method is called a download configuration dialog
will open but the downloaded file will have 0 bytes.
**Known issues**
There is a Bug with Internet Explorer 6, 7 and 8 when X-SENDFILE is used over an SSL connection, it will show
an error message like this: "Internet Explorer was not able to open this Internet site. The requested site
is either unavailable or cannot be found.". You can work around this problem by removing the
Pragma-header.
**Example**
php
Yii::$app->response->xSendFile('/home/user/Pictures/picture1.jpg');