PHP code example of sudippalash / mediauploader

1. Go to this page and download the library: Download sudippalash/mediauploader 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/ */

    

sudippalash / mediauploader 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,

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

MediaUploader::imageUpload(<UploadedFile image>, <output path>, thumb=false, name=null, $imageResize = [], $thumbResize = [0, 0]);

$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]);

$file = MediaUploader::webpUpload($request->file, 'webps', 1, null, [600, 600]);

if ($file) {
    // File is saved successfully
}

MediaUploader::anyUpload(<UploadedFile file>, <output path>, name=null);

$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]);

$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]);

$file = MediaUploader::base64ImageUpload($content, 'images', 1, null, [600, 600]);

if ($file) {
    // File is saved successfully
}

MediaUploader::contentUpload(<Content>, <output path>, name=null);

$file = MediaUploader::contentUpload($content, 'contents', 'name');

if ($file) {
    // File is saved successfully
}

MediaUploader::thumb(<output path>, <file>, $thumbPath = false, $thumbWidth = 0, $thumbHeight = 0);

$file = MediaUploader::thumb('thumbs', $file, 200, 200);

if ($file) {
    // File is saved successfully
}

[
    "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"
]

MediaUploader::delete(<path>, <file_name>, $thumb = false)

$file = MediaUploader::delete('images', $file_name, true);

if ($file) {
    // File is deleted successfully
}

MediaUploader::removeDirectory(<path>)

$path = MediaUploader::removeDirectory('images');

if ($path) {
    // Directory is deleted successfully
}

MediaUploader::fileExists(<path>, <file_name>)

if(MediaUploader::fileExists('images', $file_name)) {
    // 
}

MediaUploader::showUrl(<path>, <file_name>)

{!! MediaUploader::showUrl('images', $file_name) !!}

MediaUploader::showFile(<path>, <file_name>, <file_not_found_text|optional>)

{!! MediaUploader::showFile('images', $file_name, $empty_text) !!}

MediaUploader::showFileFromUrl(<url>, <file_name|optional>, <file_not_found_text|optional>)

{!! MediaUploader::showFileFromUrl($file_url, $file_name, $empty_text) !!}

MediaUploader::showImg(<path_or_url>, <file_name>, <array options>)

{!! 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',
]) !!}

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