Download the PHP package aleksey203/yii2-upload-behavior without Composer

On this page you can find all versions of the php package aleksey203/yii2-upload-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-upload-behavior

Yii2 file/image upload behavior for ActiveRecord

This package is the set of two similar behaviors. The first one allows you to keep the uploaded file as-is. And the second one allows you to generate set of thumbnails for the uploaded image. Behaviors could be attached multiple times for different attributes.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii-dream-team/yii2-upload-behavior "*"

or add

"yii-dream-team/yii2-upload-behavior": "*"

to the require section of your composer.json.

FileUploadBehavior

This behavior allow you to add file uploading logic with ActiveRecord behavior.

Usage

Attach the behavior to your model class:

public function behaviors()
{
    return [
        [
            'class' => '\yiidreamteam\upload\FileUploadBehavior',
            'attribute' => 'fileUpload',
            'filePath' => '@webroot/uploads/[[pk]].[[extension]]',
            'fileUrl' => '/uploads/[[pk]].[[extension]]',
        ],
    ];
}

You can use Yii path aliases like @app, @webroot, @web in your path template configuration.

You can also use additional placeholders in path templates. Placeholder [[foobar]] will be replaced with appropriate placeholder value.

Possible path/url placeholders:

Add validation rule:

public function rules()
{
    return [
        ['fileUpload', 'file'],   
    ];
}

Setup proper form enctype:

$form = \yii\bootstrap\ActiveForm::begin([
    'enableClientValidation' => false,
    'options' => [
        'enctype' => 'multipart/form-data',
    ],
]);

File should be uploading fine.

You can get uploaded file url using model call:

echo $model->getUploadedFileUrl('fileUpload');

ImageUploadBehavior

Image upload behavior extends file upload behavior with image thumbnails generation. You can configure set of different thumbnail profiles to generate.

Usage

Attach the behavior to your model class:

public function behaviors()
{
    return [
        [
             'class' => '\yiidreamteam\upload\ImageUploadBehavior',
             'attribute' => 'imageUpload',
             'thumbs' => [
                 'thumb' => ['width' => 400, 'height' => 300],
             ],
             'filePath' => '@webroot/images/[[pk]].[[extension]]',
             'fileUrl' => '/images/[[pk]].[[extension]]',
             'thumbPath' => '@webroot/images/[[profile]]_[[pk]].[[extension]]',
             'thumbUrl' => '/images/[[profile]]_[[pk]].[[extension]]',
        ],
    ];
}

You can use Yii path aliases like @app, @webroot, @web in your path template configuration.

You can also use additional placeholders in path templates. Placeholder [[foobar]] will be replaced with appropriate placeholder value.

Possible path/url placeholders:

Add validation rule:

public function rules()
{
    return [
        ['imageUpload', 'file', 'extensions' => 'jpeg, gif, png'],   
    ];
}

Setup proper form enctype:

$form = \yii\bootstrap\ActiveForm::begin([
    'enableClientValidation' => false,
    'options' => [
        'enctype' => 'multipart/form-data',
    ],
]);

File should be uploading fine.

You can get uploaded image url using model call:

echo $model->getImageFileUrl('imageUpload');

You can specify default image for models without uploaded image:

echo $model->getImageFileUrl('imageUpload', '/images/empty.jpg');

You can also get generated thumbnail image url:

echo $model->getThumbFileUrl('imageUpload', 'thumb');

You can specify default thumbnail image for models without uploaded image:

echo $model->getThumbFileUrl('imageUpload', 'thumb', '/images/thumb_empty.jpg');

Licence

MIT

Links


All versions of yii2-upload-behavior with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
yiisoft/yii2 Version *
masterexploder/phpthumb Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package aleksey203/yii2-upload-behavior contains the following files

Loading the files please wait ....