PHP code example of fsasvari / laravel-uploadify

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

    

fsasvari / laravel-uploadify example snippets


'providers' => [
    // Application Service Providers...
    // ...

    // Other Service Providers...
    Uploadify\Providers\UploadifyServiceProvider::class,
    // ...
],

'aliases' => [
    'Uploadify' => Uploadify\Facades\UploadifyManager::class,
];



namespace App;

use Uploadify\Traits\UploadifyTrait;

class Car extends Eloquent
{
    use UploadifyTrait;

    /**
     * List of uploadify files
     *
     * @var array
     */
    protected $uploadifyFiles = [
        'upload_information' => ['path' => 'documents/information'],
        'upload_specification' => ['path' => 'documents/specification', 'disk' => 's3'],
    ];
}



namespace App;

use Uploadify\Traits\UploadifyTrait;

class User extends Eloquent
{
    use UploadifyTrait;

    /**
     * List of uploadify images
     *
     * @var array
     */
    public $uploadifyImages = [
        'upload_cover' => ['path' => 'images/cover'],
        'upload_avatar' => ['path' => 'images/avatar', 'disk' => 's3'],
    ];
}



namespace App;

use Uploadify\Traits\UploadifyTrait;

class Car extends Eloquent
{
    use UploadifyTrait;

    /**
     * List of uploadify files
     *
     * @var array
     */
    public $uploadifyFiles = [
        'upload_information' => ['path' => 'documents/information'],
        'upload_specification' => ['path' => 'documents/specification'],
    ];

    /**
     * List of uploadify images
     *
     * @var array
     */
    public $uploadifyImages = [
        'upload_cover' => ['path' => 'images/cover'],
    ];
}

Route::get('{path}/{options}/{name}.{extension}', '\Uploadify\Http\Controllers\ImageController@show')
    ->where('path', '[a-z-/]+')
    ->where('options', '[a-z0-9-_,]+')
    ->where('name', '.+?')
    ->where('extension', 'jpe?g|gif|png|JPE?G|GIF|PNG');

// To use this package, first we need an instance of our model
$car = Car::first();

// get full file name with extension
$cat->upload_specification; // car-specification.pdf
$cat->upload_specification->name(); // car-specification.pdf

// get file basename
$cat->upload_specification->basename(); // car-specification

// get file extension
$cat->upload_specification->extension(); // pdf

// get file size in bytes
$cat->upload_specification->filesize(); // 1500000

// get full url path to file
$car->upload_specification->url(); // storage/documents/specification/car-specification.pdf or
                                   // http://www.website.com/storage/documents/specification/car-specification.pdf
                                   // if "url" value provided in disk url in "config/filesystems.php"

// To use this package, first we need an instance of our model
$user = User::first();

// get full image name with extension
$cat->upload_avatar; // user-avatar.jpg
$cat->upload_avatar->name(); // user-avatar.jpg

// get image basename
$cat->upload_avatar->basename(); // user-avatar

// get file extension
$cat->upload_avatar->extension(); // jpg

// get image size in bytes
$cat->upload_avatar->filesize(); // 150000

// get full url path to image
// example: http://www.website.com/storage/images/avatar/user-avatar.jpg
$car->upload_avatar->url();

// get full url path to image thumb
// example: http://www.website.com/storage/images/avatar/w_200,h_200/user-avatar.jpg
$car->upload_avatar->url(200, 200);

// get full url path to image thumb with some special effects and options
// example: http://www.website.com/storage/images/avatar/w_200,h_200,opacity_50/user-avatar.jpg
$car->upload_avatar->url(200, 200, ['opacity' => 50]);

// get full url path to image with custom options
// example: http://www.website.com/storage/images/avatar/w_500,blur_50,brightness_-50,effect_grayscale,crop_resize/user-avatar.jpg
$car->upload_avatar->url(['width' => 500, 'blur' => 50, 'brightness' => -50, 'effect' => 'grayscale', 'crop' => 'resize']);

// create new eloquent model object
$car = new Car();

// get UploadedFile from request Illuminate\Http\Request
$file = $request->file('specification');

// create new uploadify instance, set file, model and field name
$uploadify = UploadifyManager::create($file, $car, 'upload_specification'); // or set($file, new Car(), 'upload_specification')

// additional options
$uploadify->setName('custom file name'); // set custom file name

// upload file
$uploadify->upload();

// get uploaded file name with extension (without path), so you can save value in database
$car->upload_specification = $uploadify->getName();
$car->save();

// path to file
$path = '/path-to-file/file.pdf';

// create new uploadify instance, set path, model and field name
$uploadify = UploadifyManager::create($path, $car, 'upload_specification'); // or set($file, new Car(), 'upload_specification')

// create new eloquent model object
$user = new User;

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

// create new uploadify instance, set file, model and field name
$uploadify = UploadifyManager::create($file, $user, 'upload_avatar'); // or set($image, new User, 'upload_avatar');

// if you want additional image manipulation from Intervention Image package
$image = Image::make($file)->resize(800, null, function ($constraint) {
    $constraint->aspectRatio();
    $constraint->upsize();
});

$uploadify->process($image);

// additional options
$uploadify->setName('custom image name'); // set custom file name
$uploadify->setQuality(80); // set image quality, default value is 90

// upload file
$uploadify->upload();

// get uploaded file name with extension (without path), so you can save value in database
$user->upload_avatar = $uploadify->getName();
$user->save();

$car = Car::first();

// deletes file
$car->upload_specification->delete();

// you need to manually set field value to "null" after deletion
$car->upload_specification = null;
$car->save();



namespace App\Http\Controllers

use App\Car;

class CarController
{
    public function index()
    {
        $cars = Car::get();

        $data = [
            'cars' => $cars,
        ];

        return view('index', $data);
    }
}

php artisan vendor:publish --tag=uploadify

php artisan storage:link