vmorozov/laravel-file-uploads

此包提供了一种方便的方式,可以将文件上传到云存储亚马逊S3或本地快速在Laravel中

v1.1.8 2020-09-01 06:36 UTC

This package is auto-updated.

Last update: 2024-09-29 05:48:23 UTC


README

一个用于方便将文件上传到不同存储的包

安装

  1. 运行以下命令添加此包
composer require vmorozov/laravel-file-uploads
  1. 打开你的 config/app.php 并将以下内容添加到 providers 数组中
Vmorozov\FileUploads\FileUploadsServiceProvider::class
  1. 运行以下命令发布包配置文件 config/file_uploads.php
php artisan vendor:publish

配置

进入以下文件

config/file_uploads.php

在那里您可以设置

  1. 上传文件的默认存储(默认为:本地)
  2. 默认图片质量(默认为:100)
  3. 上传文件的默认文件夹(默认为: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');
}