sdtech / file-uploader-laravel
Simple library to upload image and file with validation
v1.0.6
2024-07-25 04:14 UTC
Requires
- php: ^8.1
- ext-mbstring: *
- intervention/gif: ^4.1
- intervention/image: ^3.6
README
About
A simple library that help you to to upload image and file. The current features are :
- Upload file
- Upload Image
Requirements
Installation
- From your projects root folder in terminal run:
composer require sdtech/file-uploader-laravel
- In config/app.php, add it:
'providers' => [ // Other Service Providers... Sdtech\FileUploaderLaravel\Providers\FileUploadLaravelServiceProviders::class, ],
- Publish the packages views, config file, assets, and language files by running the following from your projects root folder:
php artisan vendor:publish --tag=fileuploaderlaravel
configuration
- Go to your config folder, then open "fileuploaderlaravel.php" file
- here you must add that info or add the info to your .env file .
'ALLOWED_IMAGE_TYPE' => env('ALLOWED_IMAGE_TYPE'), 'MAX_UPLOAD_IMAGE_SIZE' => env('MAX_UPLOAD_IMAGE_SIZE') // default 2048 KB 'DEFAULT_IMAGE_FORMAT' => env('DEFAULT_IMAGE_FORMAT') // default 'webp', 'DEFAULT_IMAGE_QUALITY' => env('DEFAULT_IMAGE_QUALITY') // default 80, 'AWS_ACCESS_KEY_ID' => env('AWS_ACCESS_KEY_ID'), 'AWS_SECRET_ACCESS_KEY' => env('AWS_SECRET_ACCESS_KEY'), 'AWS_DEFAULT_REGION' => env('AWS_DEFAULT_REGION'), 'AWS_BUCKET' => env('AWS_BUCKET'), 'AWS_URL' => env('AWS_URL')
- run this commad
php artisan storage:link
sudo chmod -R 777 storage
Uses
- We provide a sample code of functionality that will help you to integrate easily
use Sdtech\FileUploaderLaravel\Service\FileUploadLaravelService; class UploadController extends Controller { public function uploadImg(Request $request) { $service = new FileUploadLaravelService(); $reqFile = $request->img; $path = 'uploads'; $response = $service->uploadImageInStorage($reqFile,$path); return $response; } } in the same way you can use other function as well
some functions
upload image in storage folder
@param FILE $reqFile (mandetory) uploaded file @param STRING $path (mandetory) file path where upload iamge @param STRING $oldFile (optional) old file name // $oldFile = '1720705563668fe21b791d2.png'; @param ARRAY $allowedImageType (optional) allowed image type like ["png","webp","jpeg"] @param INT $maxSize (optional) max upload size in KB 1024KB = 1MB @param STRING $format (optional) image output format default = webp @param INT $width (optional) image width @param INT $height (optional) image height @param INT $quality (optional) image quality default = 80
uploadImageInStorage($reqFile,$path,$old_file="",$allowedImageType=[],$maxSize="", $format='',$width="",$height=null,$quality=null)
upload image in main public folder
@param FILE $reqFile (mandetory) uploaded file @param STRING $path (mandetory) file path where upload iamge @param STRING $oldFile (optional) old file name @param ARRAY $allowedImageType (optional) allowed image type like ["png","webp","jpeg"] @param INT $maxSize (optional) max upload size in KB 1024KB = 1MB @param STRING $format (optional) image output format default = webp @param INT $width (optional) image width @param INT $height (optional) image height @param INT $quality (optional) image quality default = 80
uploadImageInPublic($reqFile,$path,$old_file="",$allowedImageType=[],$maxSize="",$format='',$width="",$height=null,$quality=null)
upload file in storage folder
@param FILE $reqFile (mandetory) uploaded file @param STRING $path (mandetory) file path where upload iamge @param STRING $oldFile (optional) old file name @param ARRAY $allowedImageType (optional) allowed image type like ["png","webp","jpeg"] @param INT $maxSize (optional) max upload size in KB 1024KB = 1MB
uploadFileInStorage($reqFile,$path,$old_file="",$allowedImageType=[],$maxSize="")
upload file in public folder
@param FILE $reqFile (mandetory) uploaded file @param STRING $path (mandetory) file path where upload iamge @param STRING $oldFile (optional) old file name @param ARRAY $allowedImageType (optional) allowed image type like ["png","webp","jpeg"] @param INT $maxSize (optional) max upload size in KB 1024KB = 1MB
ploadFileInPublic($reqFile,$path,$old_file="",$allowedImageType=[],$maxSize="")
delete file path
unlinkFile($path,$oldFile)
get file view path for storage folder
showStorageFileViewPath($path,$fileName)
get file view path for public folder
showFileViewPath($path,$fileName)
get allowed image type
allowedTypes()
get allowed file type
allowedFileExtensions()