PHP code example of adsoftteam / uploadimage

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

    

adsoftteam / uploadimage example snippets


'providers' => [
    .......
    Spatie\Glide\GlideServiceProvider::class,
    ADSoft\UploadImage\UploadImageServiceProvider::class,
]

'aliases' => [
    .......
    'GlideImage' => Spatie\Glide\GlideImageFacade::class,
    'UploadImage' => ADSoft\UploadImage\UploadImageFacade::class,
]

mix.sass('resources/assets/sass/app.scss', 'public/css/app.css').version();

mix.js(['resources/assets/js/app.js', 'resources/assets/js/upload_image_preview.js'],
    'public/js/all.js').version();

use UploadImage;

/**
 * Upload image to disk.
 *
 * @param $file object instance image or image string
 * @param $contentName string content name (use for create and named folder)
 * @param bool $watermark bool watermark status (by default = false)
 * @param bool $video if true then add watermark with video player image to an image
 * @param bool $thumbnails create thumbnails for original image
 *
 * @return object image
 * @throws UploadImageException
 */
UploadImage::upload($file, $contentName, $watermark = false, $video = false, $thumbnails = false)

$file = $request->file('image');

$video = $rubric->name == 'Video' ? true : false;
$watermark = true;
$thumbnail = true;

// Upload and save image.
try {
    // Upload and save image.
    $input['image'] = UploadImage::upload($file, 'post', $watermark, $video, $thumbnail)->getImageName();
} catch (UploadImageException $e) {

    return back()->withInput()->withErrors(['image', $e->getMessage()]);
}


/**
   * Upload file to disk.
   *
   * @param $file object file
   * @param $contentName string content name (use for create and named folder)    
   *
   * @return object image
   * @throws UploadFileException
*/
UploadImage::uploadFile($file, $contentName)

$file = $request->file('image');


// Upload and save file.
try {
    // Upload and save file.
    $input['file'] = UploadImage::uploadFile($file, 'post')->getImageName();
} catch (UploadImageException $e) {

    return back()->withInput()->withErrors(['image', $e->getMessage()]);
}


/**
 * Delete image from disk.
 *
 * @param $imageName string image name or array with images
 * @param $contentName string content name (use for folder and name)
 *
 */
UploadImage::delete($imageName, $contentName);

// Delete old image.
UploadImage::delete($post->image, 'post');

/**
 * Delete body images from disk.
 *
 * @param $textBody string with text where there images
 *
 */
UploadImage::deleteBody($textBody);

// Delete all images from post body (added in editor).
UploadImage::deleteBody($post->body);

/**
 * Create path to image.
 *
 * @param $contentName string content name (use for folder and name)
 * @param null $size integer width for image (use one of thumbnail array)
 *
 * @return mixed
 */
UploadImage::load($contentName, $size = null);

// Give all data to template.
return view('posts.index', [
    'posts' => $posts,
    'path' => UploadImage::load('post')
]);

/**
 * Preview image for form.
 *
 * @param $file object instance image
 * @param $contentName string content name (use for folder and name)
 *
 * @return array new image stream Base64
 */
UploadImage::preview($file, $contentName);

// Get image preview.
$image_url = UploadImage::preview($file, 'collage_image');

php artisan vendor:publish --provider="ADSoft\UploadImage\UploadImageServiceProvider"