orh / laravel-chunk-upload
The chunk upload for laravel
v1.1.0
2021-06-08 03:26 UTC
Requires
- php: >=7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.17.0
- phpunit/phpunit: ~6.5.0
This package is auto-updated.
Last update: 2025-03-08 11:44:00 UTC
README
The chunk upload for laravel
- 适用于 Laravel 的分片上传扩展
- PHP 7.0+
- Laravel 5.5+
- 可以配合 @orh/vue-chunk-upload 使用
- 可以结合相关的 Laravel 云存储扩展一起使用,只需配置磁盘即可
使用
- 安装
$ composer require orh/laravel-chunk-upload
- 发布配置文件
$ php artisan vendor:publish --tag=chunk-upload-config
- 使用清除命令,可以加入计划任务,每月定时清除上个月数据
// 清除上一个月的分片上传数据 $ php artisan chunk-upload:clear
- 调用
use Illuminate\Http\Request; // 预处理 app('chunk-upload')->preprocess($request); // 上传 app('chunk-upload')->save($request);
示例
- 创建控制器
$ php artisan make:controller ChunkUploadsController
- 调用
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ChunkUploadsController extends Controller { public function preprocess(Request $request) { $this->validate($request, [ 'filename' => 'required|string', 'size' => 'required|numeric|max:'.config('chunk-upload.allow_size'), ]); return app('chunk-upload')->preprocess($request); } public function upload(Request $request) { $this->validate($request, [ 'filename' => 'required|string', 'file' => 'required|file', 'total' => 'required|integer', 'index' => 'required|integer', ]); return app('chunk-upload')->save($request); } }
- 定义路由
use Illuminate\Support\Facades\Route; Route::post('chunk_uploads/preprocess', 'ChunkUploadsController@preprocess'); Route::post('chunk_uploads/upload', 'ChunkUploadsController@upload');
License
MIT