mostafaznv / php-x-sendfile
使用支持Laravel的Web服务器服务大型文件
1.1.0
2023-01-19 21:39 UTC
Requires
- php: >=7.0.1
- ext-fileinfo: *
This package is auto-updated.
Last update: 2024-09-07 21:13:09 UTC
README
使用支持Laravel的Web服务器服务大型文件
X-Sendfile的一些功能
- 支持 Nginx, Apache, LiteSpeed, Lighttpd
- 自动服务器类型检测器
- 可配置
- 支持缓存
- 设置额外头部
- 与Laravel兼容
我在开源之旅中开发 🚀,我希望我能生活在一个财务状况良好,我可以只专注于道路的环境,但正如你所知,生活并不完美。
所以如果你最终使用了我的包,请考虑进行捐赠,任何金额都会是一大步,并且非常感激。 🍺
要求
- PHP >=7.0.1
- FileInfo 扩展
安装
使用composer安装
composer require mostafaznv/php-x-sendfile
Laravel(可选)
不需要Laravel 5.5+
'providers' => [ Mostafaznv\PhpXsendfile\PhpXsendfileServiceProvider::class, ], 'aliases' => [ 'Recaptcha' => Mostafaznv\PhpXsendfile\Facades\PhpXsendfile::class, ]
php artisan vendor:publish --provider="Mostafaznv\PhpXsendfile\PhpXsendfileServiceProvider"
用法
<?php namespace App\Controllers; use Mostafaznv\PhpXsendfile\PhpXsendfile; class DownloadController { public function quickExample() { $path = '/files/Sample.mp4'; $xSendFile = new PhpXsendfile(); $xSendFile->download($path); } public function completeExample() { $path = '/files/Sample.mp4'; // or full path $path = public_path('files/Sample.mp4'); // optional $config = [ 'server' => null, 'cache' => true, 'cache-control-max-age' => 2592000 ]; // set extra headers (optional) $headers = [ 'Header-Name' => 'Header-Value' // header('Header-Name: Header-Value') ]; // set downloaded filename (optional, nullable) $fileName = 'LargeVideoFile.mp4'; $xSendFile = new PhpXsendfile($config); $xSendFile->setHeader($headers)->download($path, $fileName); } }
Laravel用法
<?php namespace App\Http\Controllers; use Mostafaznv\PhpXsendfile\Facades\PhpXsendfile; // or use PhpXsendfile; class DownloadController extends Controller { public function quickExample() { $path = public_path('files/zip.zip'); PhpXsendfile::download($path); // or app('x-sendfile')->download($path); } public function completeExample() { $path = public_path('files/zip.zip'); // set extra headers (optional) $headers = [ 'Header-Name' => 'Header-Value' // header('Header-Name: Header-Value') ]; // set downloaded filename (optional, nullable) $fileName = 'LargeVideoFile.mp4'; PhpXsendfile::setHeader($headers)->download($path, $fileName); } }
注意:要更改laravel中的配置,请打开config/x-sendfile.php并设置自己的配置。
配置
方法
下载
setHeader
我在开源之旅中开发 🚀,我希望我能生活在一个财务状况良好,我可以只专注于道路的环境,但正如你所知,生活并不完美。
所以如果你最终使用了我的包,请考虑进行捐赠,任何金额都会是一大步,并且非常感激。 🍺
致谢
本包受songlipeng2003的x-sendfile的启发。
更新日志
请参阅更新日志以获取项目的完整历史。
许可
本软件在Apache License Version 2.0下发布。
(c) 2020 Mostafaznv,版权所有。