igorw / file-serve-bundle
Symfony2 Bundle,用于提供受保护的文件。
v1.0.3
2014-01-06 20:35 UTC
Requires
Requires (Dev)
Suggests
This package is not auto-updated.
Last update: 2024-09-14 12:03:45 UTC
README
关于
FileServeBundle 允许您提供不公开的文件,例如私人附件。
安装
将包添加到您的 composer.json
{ "require": { "igorw/file-serve-bundle": "~1.0" } }
将 FileServeBundle 添加到您的应用程序内核
public function registerBundles() { $bundles = array( // ... new Igorw\FileServeBundle\IgorwFileServeBundle(), // ... ); // ... }
使用
使用 igorw_file_serve.response_factory
服务创建 FileServe 响应。默认情况下,路径相对于 app
目录。
$response = $this->get('igorw_file_serve.response_factory')->create('../VERSION', 'text/plain');
您还可以将一组选项作为 create
方法的第三个参数传递。
$options = array( 'serve_filename' => 'VERSION.txt', 'absolute_path' => true, 'inline' => false, ); $response = $this->get('igorw_file_serve.response_factory') ->create('../VERSION', 'text/plain', $options);
- serve_filename:浏览器下载文件时使用的文件名。
- absolute_path:如果启用,则包将忽略
base_dir
选项并使用提供的文件名作为绝对路径。
您还可以配置使用的工厂,例如使用 nginx XSendfile 响应工厂
igorw_file_serve: factory: sendfile # The default value is "php"
您还可以配置基本目录
igorw_file_serve: base_dir: /files/dir # The default value is "%kernel.root_dir%"
默认情况下,此包在创建响应对象时执行 file_exists
检查。最近的 nginx 版本需要相对路径,在这种情况下,PHP 中的路径不是实际的物理路径。使用 skip_file_exists
设置来禁用检查。
igorw_file_serve: skip_file_exists: true # The default value is false
支持的工厂
php
sendfile
(nginx)xsendfile
(apache)
特性
- 大文件增量提供
- Nginx XSendfile
- Apache mod_xsendfile
待办事项
- 测试
- HTTP 缓存
- HTTP 范围请求
- Lighttpd XSendfile
- 处理 PhpResponse getContent(),setContent()