oh86/laravel-uploadfile
最新稳定版本:v1.1
Composer 安装命令:
composer require oh86/laravel-uploadfile
包简介
upload/download/view file with laravel framework
README 文档
README
基于laravel框架实现的文件上传/下载/查看功能
1.安装
composer require oh86/laravel-uploadfile
php artisan vendor:publish --provider="Oh86\UploadFile\UploadFileServiceProvider"
php artisan migrate
2.配置config/uploadfile.php
return [ // 允许上传的文件类型(真正文件类型) 'allow_exts' => [ 'jpg', 'png', 'mp4', 'mov', 'pdf', 'doc', 'docx', 'xls', 'xlsx', ], // 加密机 'encryptor' => env('UPLOADFILE_ENCRYPTOR', 'local'), // 配置查看文件路由路径 'app_url' => env('UPLOADFILE_APP_URL', env('APP_URL')), 'view_file_uri' => 'file/view', 'tmp_view_file_uri' => 'file/tmp/view', // 按业务需求暴露路由路径 'routes' => [ [ 'method' => 'post', 'uri' => 'file/upload', 'action' => [\Oh86\UploadFile\Controllers\FileController::class, 'upload'], 'middlewares' => [], ], [ 'method' => 'get', 'uri' => 'file/tmp/view', 'action' => [\Oh86\UploadFile\Controllers\FileController::class, 'tmpView'], 'middlewares' => [], ], [ 'method' => 'get', 'uri' => 'file/download', 'action' => [\Oh86\UploadFile\Controllers\FileController::class, 'download'], 'middlewares' => [], ] ], ];
3.文件常见操作
use Oh86\UploadFile\Models\File; // 上传本地文件 $file = File::upload(new \SplFileInfo('/xxx/target_file.txt')); // 获取查看url $url = $file->genTmpViewFileUrl(); $url = $file->genViewFileUrl(); // 标记关联资源 $file->setAssocInfo(\App\Models\Post::class, 1); // 判断文件类型 $file->isImage(); $file->isVideo(); $file->idPdf(); $file->isWord(); $file->isExcel();
统计信息
- 总下载量: 114
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-16