PHP code example of rashiqulrony / laravel-image-upload

1. Go to this page and download the library: Download rashiqulrony/laravel-image-upload 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/ */

    

rashiqulrony / laravel-image-upload example snippets


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,

    /*
    |--------------------------------------------------------------------------
    | 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,
];

php artisan vendor:publish --provider="Rashiqulrony\LaravelImageUpload\Providers\AppServiceProvider" --tag=config
bash
php artisan storage:link

/**
* Upload an image with optional resizing and thumbnail creation.
*
* @param mixed $requestFile Uploaded file from the request.
* @param string $path Destination folder path.
* @param bool $thumb Generate thumbnail or not.
* @param string|null $name Optional custom filename.
* @param array $imageResize Resize dimensions [width, height].
* @param array $thumbResize Thumbnail dimensions [width, height].
* @return array Uploaded image information.
*/

return Uploader::imageUpload($request->image, $path, 1, $name, [300, 300], [200, 200]);

/**
* Upload a video file.
*
* @param mixed $requestFile Video file from request.
* @param string $path Destination path.
* @param string|null $name Optional custom filename.
* @return array Uploaded video file info.
*/
return Uploader::videoUpload($request->video, $path, $name);

/**
* Upload any type of file.
*
* @param mixed $requestFile File from request.
* @param string $path Destination folder path.
* @param string|null $name Optional custom filename.
* @return array Uploaded file info.
*/
return Uploader::fileUpload($request->video, $path, $name);

/**
* Upload a base64-encoded image.
*
* @param string $base64 Base64 encoded image string.
* @param string $path Destination folder path.
* @param string|null $name Optional custom filename.
* @return array Uploaded image info.
*/

return Uploader::imageUploadBase64($request->base64data, $path, $name);

return true or false;

return true or false;