shoperti/uploader
Shoperti Uploader
A file uploader for Laravel with support for preprocessing images (resize and auto orientation) using League/Glide.
Note: For auto orientation you must have a PHP installation that supports reading exif.
Installation
Add to composer
"require": {
"shoperti/uploader": "~5.8"
},
Register the package in one of your providers
public function register()
{
$this->app->register(\Shoperti\Uploader\UploaderServiceProvider::class);
}
Configuration
You can configure it through the .env file using these settings:
UPLOADER_FILES_DISK=s3
UPLOADER_FILES_SUBPATH=files
UPLOADER_FILES_FILE_NAMING=fix
UPLOADER_IMAGES_DISK=s3
UPLOADER_IMAGES_SUBPATH=images
UPLOADER_IMAGES_FILE_NAMING=fix
UPLOADER_IMAGES_RESIZE_MAX_WIDTH=1280
UPLOADER_IMAGES_RESIZE_MEMORY_LIMIT=128M
- Please refer to the config file for more details.
Use
<?php
namespace App\Http\Controllers;
// Import the Shoperti Uploader Manager in your controller
use Shoperti\Uploader\Contracts\UploaderManager;
use Shoperti\Uploader\Exceptions\DisallowedFileException;
use Shoperti\Uploader\Exceptions\InvalidFileException;
use Shoperti\Uploader\Exceptions\RemoteFileException;
// To upload or delete a file, just inject the manager either in the constructor
// or in the action method
class Controller extends BaseController
{
/**
* Uploads a file.
*
* @param \Shoperti\Uploader\Contracts\UploaderManager $uploaderManager
*/
public function upload(UploaderManager $uploaderManager)
{
try {
/** @var \Shoperti\Uploader\UploadResult uploadResult */
$uploadResult = $uploaderManager
// generate an Uploader through the manager
// using the uploaded file or the file URL as argument
->make(request()->file('file') ?: request()->input('file'))
// then call the upload() method with the location path as argument
->upload($path = 'my_files', $disk = null);
} catch (DisallowedFileException $dfe) {
// If the uploaded file has a disallowed mime-type
} catch (InvalidFileException $ife) {
// If the uploaded file is invalid
} catch (RemoteFileException $rfe) {
// If the file input was a file-url string which cannot be fetched
}
}
/**
* Deletes a file.
*
* @param \Shoperti\Uploader\Contracts\UploaderManager $uploaderManager
*/
public function delete(UploaderManager $uploaderManager)
{
$uploaderManager
->delete($disk = 's3', $filepath = \Request::input('file'))
}
}
- Please refer to the
UploadResultimplementation for more details.
Related Packages
solbeg/laravel-vue-validation
Extends Bootstrapper package. It automatically converts Laravel's request rules...
249
6
talvbansal/media-manager
A media browser and uploader for laravel apps written in vue js and bootstrap
28,310
206
solbeg/laravel-files-manager
Extended files logic for Laravel applications. Simple file uploading. Using file...
15
0
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v5.8.0 | ^7.2 | 5.7.* | | MIT | |
| v5.7.0 | ^7.2 | 5.7.* | MIT | |
| v5.6.0 | ^7.2 | 5.6.* | MIT | |
| v1.0.4 | >=5.5.9 | 5.0.*| | MIT | |
| v1.0.3 | >=5.5.9 | 5.0.*| | MIT | |
| v1.0.2 | >=5.5.9 | 5.0.*| | MIT | |
| v1.0.1 | >=5.5.9 | 5.0.*| | MIT | |
| v1.0.0 | >=5.5.9 | 5.0.*| | MIT |