1. Go to this page and download the library: Download tigrov/yii2-photo-widget 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/ */
tigrov / yii2-photo-widget example snippets
class Model extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'upload' => [
'class' => '\tigrov\uploadBehavior\UploadBehavior',
'path' => '@runtime/upload',
'attributes' => ['photo'],
// 'saveCallback' => ['\tigrov\photoWidget\PhotoWidgetHelper', 'crop'],
// or if you need to crop and resize
'saveCallback' => function ($model, $attribute, $file, $filename) {
$width = 200;
$height = 200;
\tigrov\photoWidget\PhotoWidgetHelper::crop($model, $attribute, $file, $filename, $width, $height);
}
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['photo'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png,jpg,jpeg'],
];
}
}
class FormController extends \yii\web\Controller
{
public function actionUpload()
{
$model = new Model();
if ($model->load(\Yii::$app->request->post()) && $model->save()) {
\Yii::$app->session->setFlash('success', 'Model is saved.');
return $this->refresh();
}
return $this->render('form', [
'model' => $model,
]);
}
}
$form = ActiveForm::begin();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.