1. Go to this page and download the library: Download tigrov/yii2-upload-behavior 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-upload-behavior example snippets
class Model extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'upload' => [
'class' => '\tigrov\uploadBehavior\UploadBehavior',
'path' => '@runtime/upload',
'attributes' => ['file'],
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['file'], 'file', 'skipOnEmpty' => false],
];
}
}
class FormController extends \yii\web\Controller
{
public function actionUpload()
{
$model = new Model();
if ($model->load(\Yii::$app->request->post()) && $model->save()) {
\Yii::$app->getSession()->setFlash('success', 'Model is saved.');
return $this->refresh();
}
return $this->render('form', [
'model' => $model,
]);
}
}
php composer.phar
$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.