All Projects → rymanalu → Laravel Simple Uploader

rymanalu / Laravel Simple Uploader

Licence: mit
Simple file uploader for Laravel 5.

Projects that are alternatives of or similar to Laravel Simple Uploader

ic-firebase-uploader
This component is a multi-file uploader for firebase
Stars: ✭ 21 (-64.41%)
Mutual labels:  upload, file, uploader
Aetherupload Laravel
A Laravel package to upload large files 上传大文件的Laravel扩展包
Stars: ✭ 835 (+1315.25%)
Mutual labels:  laravel, upload, file
Chibisafe
Blazing fast file uploader and awesome bunker written in node! 🚀
Stars: ✭ 657 (+1013.56%)
Mutual labels:  upload, file, uploader
Uploadcare Widget
Uploadcare Widget, an ultimate tool for HTML5 file upload supporting multiple file upload, drag&drop, validation by file size/file extension/MIME file type, progress bar for file uploads, image preview.
Stars: ✭ 183 (+210.17%)
Mutual labels:  upload, file, uploader
Droply Js
Droply JS, a new responsive and cross browser chunk uploader with DragDrop and File Preview capabilities (HTML5/CSS3)
Stars: ✭ 50 (-15.25%)
Mutual labels:  upload, file, uploader
Laravel Filemanager Example 5.3
Demo integration for laravel-filemanager (https://github.com/UniSharp/laravel-filemanager).
Stars: ✭ 100 (+69.49%)
Mutual labels:  laravel, upload, file
Angular File Uploader
Angular file uploader is an Angular 2/4/5/6/7/8/9/10 + file uploader module with Real-Time Progress Bar, Responsive design, Angular Universal Compatibility, localization and multiple themes which includes Drag and Drop and much more.
Stars: ✭ 92 (+55.93%)
Mutual labels:  upload, file, uploader
Laravel Filemanager
Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
Stars: ✭ 1,688 (+2761.02%)
Mutual labels:  laravel, upload, file
ShareX-CDN
Basic image, text & file uploader CDN for ShareX
Stars: ✭ 22 (-62.71%)
Mutual labels:  upload, file, uploader
Laravel Imageup
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image
Stars: ✭ 646 (+994.92%)
Mutual labels:  laravel, upload
Transit
Easy file uploading and downloading for Laravel 5.
Stars: ✭ 5 (-91.53%)
Mutual labels:  laravel, upload
Web File Uploader
A simple tool to let people upload and share images and files
Stars: ✭ 26 (-55.93%)
Mutual labels:  file, uploader
Cj Upload
Higher order React components for file uploading (with progress) react file upload
Stars: ✭ 589 (+898.31%)
Mutual labels:  upload, file
Laravel Guided Image
Simplified and ready image manipulation for Laravel through intervention image.
Stars: ✭ 32 (-45.76%)
Mutual labels:  laravel, upload
Filegator
Powerful Multi-User File Manager
Stars: ✭ 587 (+894.92%)
Mutual labels:  file, uploader
Fileup
FileUp - JQuery File Upload
Stars: ✭ 10 (-83.05%)
Mutual labels:  upload, file
Pomf
Simple file uploading and sharing
Stars: ✭ 535 (+806.78%)
Mutual labels:  upload, file
Upload
文件上传功能
Stars: ✭ 8 (-86.44%)
Mutual labels:  upload, uploader
Resumable.php
PHP backend for resumable.js
Stars: ✭ 32 (-45.76%)
Mutual labels:  upload, file
Kbframe
一款基于Laravel框架开发的现代化二次开发框架,是高性能,高效率,高质量的企业级开发框架,具有驱动领域,敏捷开发,轻易上手,高内聚低耦合,开箱即用等特点。
Stars: ✭ 47 (-20.34%)
Mutual labels:  laravel, upload

Laravel 5 Simple Uploader

Build Status Total Downloads Latest Stable Version License

Uploading files and store its in Filesystem / Cloud storage in Laravel 5 is not easy and simple for some developers. This package provides a simple way to do that, and comes with fluent interface that you might like.

Installation

First, install this package via the Composer package manager:

composer require rymanalu/laravel-simple-uploader

Next, you should add the UploaderServiceProvider to the providers array of your config/app.php configuration file:

Rymanalu\LaravelSimpleUploader\UploaderServiceProvider::class,

Don't forget to add the Uploader facade to the aliases array for shorter code:

'Uploader' => Rymanalu\LaravelSimpleUploader\Support\Uploader::class,

After that, you should publish the Uploader configuration using the vendor:publish Artisan command. This command will publish the uploader.php configuration file to your config directory:

php artisan vendor:publish --provider="Rymanalu\LaravelSimpleUploader\UploaderServiceProvider"

Configuration

The Uploader configuration is located at config/uploader.php, where you can adjust the default file provider and the default file visibility as you want.

File Providers

This package comes with two file providers, from HTTP request and local filesystem. Before uploading a file, you can set where the file is provided. Example:

Uploader::from('request')->upload('avatar'); // see the supported providers at config/uploader.php

// Or you can use the magic methods...
Uploader::fromRequest()->upload('file');
Uploader::fromLocal()->upload('/path/to/file');
Uploader::fromUrl()->upload('https://via.placeholder.com/150.png');

If you call method on the Uploader facade without first calling the from method, the uploader will assume that you want to use the default provider.

// If your default provider is local, it will automatically use the local provider.
Uploader::upload('/path/to/file');

Usage

Uploading a File

Now, uploading a file is very simple like this:

<?php

namespace App\Http\Controllers;

use Uploader;
use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * Change user's avatar.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function changeAvatar(Request $request)
    {
        Uploader::upload('avatar');

        //
    }
}

The upload method accept a request key or path where the file is located (based on the file provider) as first parameter and returns a boolean: true if succeed or false if failed.

You may pass a Closure callback as second parameter that will be called if the file successfully uploaded:

// The parameter in the Closure is a full uploaded filename...
Uploader::upload('avatar', function ($filename) {
    Photo::create(['photo' => $filename]);
});

Uploader::upload('/path/to/file', function ($filename) {
    $user = User::find(12);

    $user->update(['avatar' => $filename]);
});

Choosing the File Storage

Automatically, the Uploader will use your default Filesystem Disk when storing the file. But, you can choose where you will store the file with uploadTo method:

// see the supported uploadTo parameter at config/filesystems.php
Uploader::uploadTo('s3')->upload('avatar');

// Or you can use the magic methods...
Uploader::uploadToS3();
Uploader::uploadToFtp();
Uploader::uploadToLocal();
Uploader::uploadToRackspace();

Set the Folder

Maybe you want to specify the folder where the file will be stored. Just use the toFolder method:

Uploader::toFolder('photos')->upload('photo');

Rename the File

Adjust the filename as you want with renameTo method:

Uploader::renameTo('my-awesome-videos')->upload('/path/to/video');

If you ignore this method, the file will be renamed to random and unique name.

File Visibility

You may set the file visibility using the setVisibility method:

Uploader::setVisibility('public')->upload('avatar');

Or just ignore this, and the Uploader will set the visibility based on your configuration.

Method Chainning

All the methods above except the upload method, are chainable. Feel free to call other methods before calling the upload. Example:

Uploader::from('local')->uploadToS3()->toFolder('banners')->renameTo('cool-banner')->setVisibility('public')->upload('/path/to/banner');

Adding Custom File Provider

Implementing The Provider

Your custom file provider should implement the Rymanalu\LaravelSimpleUploader\Contracts\Provider. This interface contains just a few simple methods we need to implement. A stubbed Google Drive implementation looks something like this:

<?php

// You are free to place the providers anywhere you like...
namespace App\Uploader\Providers;

// Check this interface to see all the docblock for each method...
use Rymanalu\LaravelSimpleUploader\Contracts\Provider;

class GoogleDrive implements Provider
{
    public function isValid() {}
    public function getContents() {}
    public function getExtension() {}
    public function setFile($file) {} // Or you can use Rymanalu\LaravelSimpleUploader\Support\FileSetter trait to implement this method...
}

Registering The Provider

Once your provider has been implemented, you are ready to register it with the UploaderManager. To add additional drivers to the manager, you may use the extend method on the Uploader facade. You should call the extend method from the boot method of a service provider. You may do this from the existing AppServiceProvider or create an entirely new provider:

<?php

namespace App\Providers;

use App\Uploader\Providers\GoogleDrive;
use Illuminate\Support\ServiceProvider;
use Rymanalu\LaravelSimpleUploader\Support\Uploader; // Or just "use Uploader;" if you register the facade in the aliases array in "config/app.php" before...

class UploaderServiceProvider extends ServiceProvider
{
    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    public function boot()
    {
        Uploader::extend('gdrive', function ($app) {
            // Return implementation of Rymanalu\LaravelSimpleUploader\Contracts\Provider...
            return new GoogleDrive;
        });
    }

    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Once the provider driver has been registered, you may use the gdrive driver in your config/uploader.php configuration file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].