vmorozov / laravel-file-uploads
此包提供了一种方便的方式,可以将文件上传到云存储亚马逊S3或本地快速在Laravel中
v1.1.8
2020-09-01 06:36 UTC
Requires
- php: >=7.0
- illuminate/http: >=5.4
- illuminate/support: >=5.4
- intervention/image: ^2.4|^6.0
- league/flysystem: ^1.0
- league/flysystem-aws-s3-v3: ^1.0
README
一个用于方便将文件上传到不同存储的包
安装
- 运行以下命令添加此包
composer require vmorozov/laravel-file-uploads
- 打开你的
config/app.php
并将以下内容添加到 providers 数组中
Vmorozov\FileUploads\FileUploadsServiceProvider::class
- 运行以下命令发布包配置文件 config/file_uploads.php
php artisan vendor:publish
配置
进入以下文件
config/file_uploads.php
在那里您可以设置
- 上传文件的默认存储(默认为:本地)
- 默认图片质量(默认为:100)
- 上传文件的默认文件夹(默认为:public/user-uploads)
用法
上传文件
public function store(Request $request) { // This will upload your file to the default folder of selected in config storage Uploader::uploadFile($request->file('some_file')); // This will upload your file to the given as second parameter path of default storage Uploader::uploadFile($request->file('some_file'), 'path/to/upload'); // This will upload your file to the given storage Uploader::uploadFile($request->file('some_file'), 'path/to/upload', 'storage_name'); // This will also resize image to the given width and height Uploader::uploadFile($request->file('some_file'), 'path/to/upload', 'storage_name'); }
上传图片的base64字符串
public function store(Request $request) { // This will upload your file to the default folder of selected in config storage Uploader::uploadBase64Image($request->input('image')); // This will upload your file to the given as second parameter path of default storage Uploader::uploadFile($request->input('image'), 'path/to/upload'); // This will upload your file to the given storage Uploader::uploadFile($request->input('image'), 'path/to/upload', 'storage_name'); // This will also resize image to the given width and height Uploader::uploadFile($request->input('image'), 'path/to/upload', 'storage_name'); }