- Overview
- Installation & Uninstallation
- Local and remote management using IIS 7
- Context and processing order
- Apache compatibility
- Modules
- core functions
- mod_antibot
- mod_asis
- mod_auth_basic
- mod_auth_digest
- mod_authn_anon
- mod_authn_dbd
- mod_authn_default
- mod_authn_file
- mod_authz_default
- mod_authz_groupfile
- mod_authz_host
- mod_authz_user
- mod_cache
- mod_dbd
- mod_deflate
- mod_developer
- mod_dir
- mod_disk_cache
- mod_env
- mod_evasive
- mod_expires
- mod_filter
- mod_gzip
- mod_headers
- mod_hotlink
- mod_linkfreeze
- mod_log_config
- mod_logio
- mod_mem_cache
- mod_mime
- mod_proxy
- mod_replace
- mod_rewrite
- mod_seo
- mod_setenvif
- mod_so
- mod_speling
- mod_usertrack
- mod_xsendfile
- Articles
- Release history
- Troubleshooting
- License agreement
mod_xsendfile
Overview
mod_xsendfile module handles X-SENDFILE headers registered by the original output handler. If the module finds X-SENDFILE header, it discards the output and instead sends the file specified by that header using Ape core functions.
It is useful to:
- Speed-up statics downloading for CMS (by avoiding reading/sending file via script engine)
- Check user ability to download (e.g. checking quota in database)
- Record downloads statistics (advanced download counter)
- Flexible configuration of 'Expires' header
Quick start
Having mod_xsendfile enabled, you may use the following code to initiate downloading (not processing) of hello.txt
httpd.conf:
XSendFilePath c:/inetpub/wwwroot/data
.htaccess:
XSendFile On
PHP script:
<?php
//set proper Content-Type
header('Content-Type: plain/text');
//force download box with the filename hello.txt
header('Content-Disposition: attachment;filename=hello.txt');
//file is located at c:/inetpub/wwwroot/data/hello.txt
header('X-Sendfile: c:/inetpub/wwwroot/data/hello.txt');
?>
Related articles and topics
Directives
Name | Context | Description |
---|---|---|
XSendFile | S V D .h | enables processing of X-SENDFILE header |
XSendFilePath | S V D .h | specifies the allowed paths to serve files using mod_xsendfile |
XSendFileAllowAbove | S V D .h |
allows sending files above Request path (deprecated now, use XSendFilePath instead)
|
XSendFile
When On , enables processing of X-SENDFILE header.
Syntax
XSendFile On|Off
Description
XSendFile
directive sends the file specified in X-SENDFILE header instead of the handler output.
If the response lacks the X-SENDFILE header, nothing will happen.
By default mod_xsendfile will allow downloads from the directory of the current request or below.
To enable downloads from other locations use XSendFilePath
directive.
Example
<Files out.php>
XSendFile On
</Files>
XSendFilePath
Specifies the allowed paths to serve files using mod_xsendfile
Syntax
XSendFilePath path ...
Description
By default mod_xsendfile will allow downloads from the directory of the current request or below.
XSendFilePath
enables downloads from any locations.
Paths must be absolute, e.g. starting with drive letter: c:\
or d:\
.
Example
<VirtualHost www.example.com>
XSendFilePath c:\inetpub\downloads d:\site\data\images
</Location>
XSendFileAllowAbove
Deprecated! Allows or disallows sending files above Request path.
Syntax
XSendFileAllowAbove On|Off
Description
XSendFileAllowAbove
directive, when set, allows sending
files not below the path of the Request (this refers to the request URI not the translated path).
Example
<VirtualHost www.example.com>
XSendFileAllowAbove On
</VirtualHost>