PHP code example of punjabideveloper / yii2-cropper

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

    

punjabideveloper / yii2-cropper example snippets


class Form extends \yii\base\Model
{
    public $image;

    public function rules()
    {
        return [
            ['image', 'image', 'enableClientValidation' => FALSE],
        ];
    }
}

$form->field($model, 'image')
    ->widget(\fv\yii\Cropper\Widget::class)

if ($app->request->isPost) {
   $form->image = \fv\yii\Cropper\UploadedFile::getInstance($form, 'image');

   if ($form->validate())
   {
        $name = '/tmp/' . $form->image->baseName
            . '.' . $form->image->extension;
            
        $form->image->saveAs($name);
        $app->session->setFlash('success',
            'Saved to ' . Html::encode($name));
        return $this->refresh();
    }
}