Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rymanalu/laravel-simple-uploader
Simple file uploader for Laravel 5.
https://github.com/rymanalu/laravel-simple-uploader
file laravel php upload uploader
Last synced: about 1 month ago
JSON representation
Simple file uploader for Laravel 5.
- Host: GitHub
- URL: https://github.com/rymanalu/laravel-simple-uploader
- Owner: rymanalu
- License: mit
- Created: 2016-12-08T16:05:53.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-10T11:50:47.000Z (about 6 years ago)
- Last Synced: 2024-10-31T07:48:52.449Z (about 1 month ago)
- Topics: file, laravel, php, upload, uploader
- Language: PHP
- Size: 29.3 KB
- Stars: 56
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-indo-projects - Laravel Simple Uploader - Simple file uploader for Laravel 5. (Laravel)
- awesome-indonesia-repo - Laravel Simple Uploader - Simple file uploader for Laravel 5. (Laravel)
README
# Laravel 5 Simple Uploader
[![Build Status](https://travis-ci.org/rymanalu/laravel-simple-uploader.svg?branch=1.0)](https://travis-ci.org/rymanalu/laravel-simple-uploader) [![Total Downloads](https://poser.pugx.org/rymanalu/laravel-simple-uploader/downloads)](https://packagist.org/packages/rymanalu/laravel-simple-uploader) [![Latest Stable Version](https://poser.pugx.org/rymanalu/laravel-simple-uploader/v/stable)](https://packagist.org/packages/rymanalu/laravel-simple-uploader) [![License](https://poser.pugx.org/rymanalu/laravel-simple-uploader/license)](https://packagist.org/packages/rymanalu/laravel-simple-uploader)
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:
```php
Rymanalu\LaravelSimpleUploader\UploaderServiceProvider::class,
```Don't forget to add the `Uploader` facade to the `aliases` array for shorter code:
```php
'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:
```php
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.
```php
// 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
$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](https://laravel.com/docs/filesystem) Disk when storing the file. But, you can choose where you will store the file with `uploadTo` method:
```php
// 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:
```php
Uploader::toFolder('photos')->upload('photo');
```### Rename the File
Adjust the filename as you want with `renameTo` method:
```php
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](https://laravel.com/docs/filesystem#file-visibility) using the `setVisibility` method:
```php
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:
```php
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