sudippalash/mediauploader is a Laravel package for laravel package for media uploader.
It currently has 5 GitHub stars and 1.096 downloads on Packagist (latest version 2.0.6).
Install it with composer require sudippalash/mediauploader.
Discover more Laravel packages by sudippalash
or browse all Laravel packages to compare alternatives.
Last updated
mediauploader is a simple file-handling package for Laravel that provides various options for managing files, including image uploads, file uploads, WebP uploads, base64 image uploads, image uploads from URLs, and Google image content uploads. The package currently supports public, local, and s3 storage (note: only publicly accessible S3 buckets are supported).
It also includes file and image preview functionality.
Via Composer
composer require sudippalash/mediauploader
You should publish the config file with:
php artisan vendor:publish --provider="Sudip\MediaUploader\Providers\AppServiceProvider" --tag=config
In config/mediauploader.php config file you should set mediauploader global path.
return [
/*
|--------------------------------------------------------------------------
| Base Directory
|--------------------------------------------------------------------------
|
| base_dir stores all other directory inside storage folder of your laravel application by default
| if you specify any name. all storage will be done inside that directory or name that you specified
|
*/
'base_dir' => null,
/*
|--------------------------------------------------------------------------
| Thumb Directory
|--------------------------------------------------------------------------
|
| thumb_dir creates another folder inside the directory as a "thumb" by default
| you can change the name thumb to any other name you like.
*/
'thumb_dir' => 'thumb',
/*
|--------------------------------------------------------------------------
| Timestamp Prefix
|--------------------------------------------------------------------------
|
| If timestamp_prefix is true then create a file with a timestamp to ignore the same name image replacement. Example: image-1658562981.png.
| If timestamp_prefix is false then the script checks file exists or not if the file exists then add the time() prefix for the new file otherwise leave it as the file
| name.
*/
'timestamp_prefix' => false,
/*
|--------------------------------------------------------------------------
| Thumb Image Height Width
|--------------------------------------------------------------------------
|
| specify the thumb image ratio of height and weight by default it takes 300px X 300px
*/
'image_thumb_height' => 300,
'image_thumb_width' => 300,
/*
|--------------------------------------------------------------------------
| Fake Image Url
|--------------------------------------------------------------------------
|
| fake_image_url , if you specify a fake image path or url here. the entire package will use
| this image when there is no image found. or you can specify the fake image in the
| function parameter as well.
| Example: 'fake_image_url' => 'images/fake.png' or 'fake_image_url' => 'https://example.com/images/fake.png,
*/
'fake_image_url' => null,
/*
|--------------------------------------------------------------------------
| Folder permission
|--------------------------------------------------------------------------
|
| path_permission , if you create a folder in your project then you can define your folder permission.
| Example: null, 0755, 0777
*/
'path_permission' => 0777,
];
Before using this, you must complete the following steps (if you want to use the default filesystem disk, which is public):
FILESYSTEM_DISK=public
php artisan storage:link
MediaUploader::disk('local')->usageFunction();
MediaUploader::imageUpload(<UploadedFile image>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);
Example:
$file = MediaUploader::imageUpload($request->file, 'images', 1, null, [600, 600]);
if ($file) {
// File is saved successfully
}
MediaUploader::webpUpload(<UploadedFile image>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);
Example:
$file = MediaUploader::webpUpload($request->file, 'webps', 1, null, [600, 600]);
if ($file) {
// File is saved successfully
}
MediaUploader::anyUpload(<UploadedFile file>, <output path>, name=null);
Example:
$file = MediaUploader::anyUpload($request->file, 'files', 'filename');
if ($file) {
// File is saved successfully
}
MediaUploader::imageUploadFromUrl(<Valid Image URL>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);
Example:
$file = MediaUploader::imageUploadFromUrl($url, 'images', 1, null, [600, 600]);
if ($file) {
// File is saved successfully
}
MediaUploader::base64ImageUpload(<base64 Content>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);
Example:
$file = MediaUploader::base64ImageUpload($content, 'images', 1, null, [600, 600]);
if ($file) {
// File is saved successfully
}
MediaUploader::contentUpload(<Content>, <output path>, name=null);
Example:
$file = MediaUploader::contentUpload($content, 'contents', 'name');
if ($file) {
// File is saved successfully
}
MediaUploader::thumb(<output path>, <file>, $thumbPath = false, $thumbWidth = 0, $thumbHeight = 0);
Example:
$file = MediaUploader::thumb('thumbs', $file, 200, 200);
if ($file) {
// File is saved successfully
}
Returns:
Response from every function looks like this
[
"name" => "example-image.jpg"
"originalName" => "example-image.jpg"
"size" => 148892
"width" => 600
"height" => 600
"mime_type" => "image/jpeg"
"ext" => "jpg"
"url" => "http://localhost/storage/test/example-image.jpg"
]
File Delete
MediaUploader::delete(<path>, <file_name>, $thumb = false)
Example:
$file = MediaUploader::delete('images', $file_name, true);
if ($file) {
// File is deleted successfully
}
Directory Delete
MediaUploader::removeDirectory(<path>)
Example:
$path = MediaUploader::removeDirectory('images');
if ($path) {
// Directory is deleted successfully
}
MediaUploader::fileExists(<path>, <file_name>)
Example:
if(MediaUploader::fileExists('images', $file_name)) {
//
}
MediaUploader::showUrl(<path>, <file_name>)
Example:
{!! MediaUploader::showUrl('images', $file_name) !!}
MediaUploader::showFile(<path>, <file_name>, <file_not_found_text|optional>)
Example:
{!! MediaUploader::showFile('images', $file_name, $empty_text) !!}
MediaUploader::showFileFromUrl(<url>, <file_name|optional>, <file_not_found_text|optional>)
Example:
{!! MediaUploader::showFileFromUrl($file_url, $file_name, $empty_text) !!}
MediaUploader::showImg(<path_or_url>, <file_name>, <array options>)
Example:
{!! MediaUploader::showImg($pathOrUrl, $file_name, [
'thumb' => true, // If thumb image store via upload function.
'popup' => true, // Currently support only jQuery fancybox.
'fakeImg' => 'images/avatar.png', // Pass fake image path without url or pass true (if pass true it will generate fake image from config file fake_image_url value).
'id' => 'image',
'class' => 'img-fluid',
'style' => '',
'alt' => 'Nice Image',
]) !!}