PHP code example of sdtech / file-uploader-laravel

1. Go to this page and download the library: Download sdtech/file-uploader-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sdtech / file-uploader-laravel example snippets


'providers' => [
    // Other Service Providers...
    Sdtech\FileUploaderLaravel\Providers\FileUploadLaravelServiceProviders::class,
],

'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')

php artisan storage:link

sudo chmod -R 777 storage


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

@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) 

@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) 

@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="")
    
@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="")

unlinkFile($path,$oldFile)

showStorageFileViewPath($path,$fileName)

showFileViewPath($path,$fileName)

allowedTypes()

allowedFileExtensions()
bash
php artisan vendor:publish --tag=fileuploaderlaravel