PHP code example of alex-dwt / file

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

    

alex-dwt / file example snippets


php composer.phar 

"flexibuild/file": "*"

    // ...
    public function behaviors()
    {
        return [
            'fileModelBehavior' => [
                'class' => \flexibuild\file\ModelBehavior::className(),
                'attributes' => [
                    // add 'avatarFile' attribute that will be linked with 'avatar' property
                    // and use 'contact' context
                    'avatar' => 'contact',
                ],
            ],
        ];
    }
    // ...

    public function rules()
    {
        return [
            // ...
            ['avatarFile', 'file'/*, 'skipOnEmpty' => false */],
            // ... 
        ];
    }

    
        use flexibuild\file\widgets\bootstrap\ActiveFormEx;
        // or flexibuild\file\widgets\ActiveFormEx without using bootstrap
    

    // ...
    'controllerMap' => [
        'file' => [
            'class' => 'flexibuild\file\web\UploadController',
            'contexts' => [
                'contact',
            ],
        ],
    ],
    // ...

    <?= \flexibuild\file\widgets\BlueimpJQueryUploader::widget([
        'model' => $model,
        'attribute' => 'avatarFile',
        'url' => ['file/upload-contact'],
    ]) 

    <?= $form->field($model, 'avatarFile')->fileBlueimpUploader([
        'url' => ['file/upload-contact'],
    ]) 

    <a href="<?= Html::encode($model->avatarFile)