PHP code example of amirsahra / illustrator

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

    

amirsahra / illustrator example snippets


// Upload the image with the default values set in the config file of this package
Illustrator::upload($request->imageFieldName);

// Upload the image to the desired directory
Illustrator::setDir('images/users')->upload($request->imageFieldName);

// Upload the image to the desired name
Illustrator::setName('myDesiredName')->upload($request->imageFieldName);

// Upload the image to the desired disk
Illustrator::setDisk('public')->upload($request->imageFieldName);

//You can use this method together, but the upload method must be at the end.
Illustrator::setDisk('public')
    ->setName('myDesiredName')
    ->setDir('images/users')
    ->upload($request->imageFieldName);

Illustrator::setDisk('public')
    ->setName('myDesiredName')
    ->setDir('images/users')
    ->update($request->imageFieldName,$imagePath);

composer 

Amirsahra\Illustrator\IllustratorServiceProvider::class,

php artisan vendor:publish --tag="illustrator"

php artisan config:clear

composer dump-autoload

php artisan storage:link

  id,
  path,
  created_at,
  updated_at

use Amirsahra\Illustrator\Facade\Illustrator;

Illustrator::upload($request->imageFieldName);

<form method="post" action="{{route('uploadImage')}}" enctype="multipart/form-data">
    <input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
    <div>
        <label for="file">Choose file to upload</label>
        <input type="file" id="file" name="imageInput" multiple/>
    </div>
    <div>
        <button type="submit">Submit</button>
    </div>
</form>

namespace App\Http\Controllers;

use Amirsahra\Illustrator\Facade\Illustrator;
use App\MyImage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class HomeController extends Controller
{
    public function uploadImage(Request $request)
    {
        $imgPath = Illustrator::upload($request->imageInput);
        MyImage::create([
            'path' => $imgPath
        ]);

        return Redirect::back()->with(['msg' => 'successfully']);
    }
}

namespace App\Http\Controllers;

use Amirsahra\Illustrator\Facade\Illustrator;
use App\MyImage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class HomeController extends Controller
{
    public function uploadImage(Request $request)
    {
        $imgPath = Illustrator::setDir('myDirectory/images')->upload($request->imageInput);
        MyImage::create([
            'path' => $imgPath
        ]);

        return Redirect::back()->with(['msg' => 'successfully']);
    }
}

namespace App\Http\Controllers;

use Amirsahra\Illustrator\Facade\Illustrator;
use App\MyImage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class HomeController extends Controller
{
    public function uploadImage(Request $request)
    {
        $imgPath = Illustrator::setName('imageName')->upload($request->imageInput);
        MyImage::create([
            'path' => $imgPath
        ]);

        return Redirect::back()->with(['msg' => 'successfully']);
    }
}

namespace App\Http\Controllers;

use Amirsahra\Illustrator\Facade\Illustrator;
use App\MyImage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class HomeController extends Controller
{
    public function uploadImage(Request $request)
    {
        $imgPath = Illustrator::setDisk('public')->upload($request->imageInput);
        MyImage::create([
            'path' => $imgPath
        ]);

        return Redirect::back()->with(['msg' => 'successfully']);
    }
}

<img src="{{asset("storage/myDirectory/images/imageName.png")}}" alt="image" >

Storage::disk('local')->download('myDirectory/images/imageName.png');

namespace App\Http\Controllers;

use Amirsahra\Illustrator\Facade\Illustrator;
use App\MyImage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class HomeController extends Controller
{
    public function uploadImage(Request $request)
    {
        $imgPath = Illustrator::setName('imageName')
            setDir('myDirectory/images')
            setDisk('public')
            ->upload($request->imageInput);
            
        MyImage::create([
            'path' => $imgPath
        ]);

        return Redirect::back()->with(['msg' => 'successfully']);
    }
}

use Amirsahra\Illustrator\Facade\Illustrator;
use App\MyImage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;

class HomeController extends Controller
{
public function updateImage(Request $request,MyImage $myImage)
{
    $newImgPath = Illustrator::setName('imageName')
        setDir('myDirectory/images')
        setDisk('public')
        ->update($request->imageInput,$myImage->path);

        $myImage->update([
            'path' => $newImgPath
        ]);

        return Redirect::back()->with(['msg' => 'update image successfully']);
    }
}