dosarkz/laravel-uploader

此包的最新版本(0.2.4)没有可用的许可证信息。

laravel 5 的上传类

0.2.4 2017-12-22 06:47 UTC

This package is auto-updated.

Last update: 2024-09-29 04:08:56 UTC


README

Laravel 5 图像和文件上传器,带有缩放功能 http://image.intervention.io/

安装

composer require dosarkz/laravel-uploader

添加到 config/app.php

提供者

Dosarkz\LaravelUploader\Provider\LaravelUploaderServiceProvider::class

别名

'Uploader' => Dosarkz\LaravelUploader\Facade\LaravelUploaderFacade::class
  

示例图像上传

Uploader::image(uploaded_file, destination, resize, imageWidth, imageHeight, thumbWidth, thumbHeight)
  • @uploaded_file - 上传文件的实例
  • @destination - 图像的路径,例如 'images/articles',字符串
  • @resize - 一个参数,用于确定是否使用压缩。如果使用,需要填写以下参数之一:图像的分辨率,true 或 false,布尔值
  • @imageWidth, @imageHeight - 图像的像素参数,例如 100,数字
  • @thumbWidth, @thumbHeight - 缩略图的像素参数,例如 100,数字
  use Uploader;
  
  $image_uploader  = Uploader::image($request->file('avatar'));
  $image = Image::create([
      'name' => $image_uploader->getFileName(),
      'thumb' => $image_uploader->getThumb(),
      'path' => $image_uploader->getDestination(),
  ]);

示例文件上传

Uploader::file(uploaded_file, destination)
  • @uploaded_file - 上传文件的实例
  • @destination - 图像的路径,例如 'images/articles',字符串
use Uploader;
  
 $image_uploader  = Uploader::file($request->file('file'));

  $file = File::create([
      'name' => $image_uploader->getFileName(),
      'path' => $image_uploader->getDestination(),
      'user_id' => auth()->user()->id
  ]);