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

On this page you can find all versions of the php package nedarta/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

UploadBehavior for Yii2

Full-featured Yii2 image upload behavior with advanced processing capabilities.

Features

Requirements

Installation

Install via Composer:

The extension will automatically install the required dependency yiisoft/yii2-imagine.

Configure the @upload alias in your application config:

Basic Usage

Simple Configuration

Form Example

Controller Example

Multiple Image Uploads

Use MultipleUploadBehavior to store multiple images per model in a related table (one-to-many gallery). It reuses the full processing pipeline (EXIF auto-rotation, variants, format conversion) for every uploaded file.

Behavior Configuration

Related Model and Migration

Add a relation on the owner model for display:

Form

The file input name must end with []:

Displaying the Gallery

Update Semantics

Configuration Options

Basic Properties

Property Type Default Description
uploadAttribute string 'upload' Virtual attribute that receives the UploadedFile
imageAttribute string 'image' Database attribute where filename is stored
uploadAlias string required Yii alias for storage folder
baseName string|Closure 'image' Base filename before random number
autoRotate bool true Reserved flag (auto-rotation currently always runs)
forceConvert string|null null Force output format: 'jpg', 'png', 'webp', 'jpeg'
variants array ['' => ['resize' => [2500, 2500]]] Variant definitions

Base Name with Closure

EXIF Auto-Rotation

By default, images are automatically rotated based on their EXIF orientation data (common with phone cameras).

Note: Auto-rotation only works with JPEG files and requires the PHP EXIF extension. The autoRotate flag is present for future control, but in the current version rotation always runs when EXIF orientation is detected.

Format Conversion

Force all images (original and variants) to a specific format:

Supported formats: jpg, jpeg, png, webp

Image Variants

Simple Variants

This creates:

Variant Options

Resize

Maintains aspect ratio, scales down to fit within dimensions:

Thumbnail

Crops to exact dimensions:

Smart Crop

Intelligent cropping (requires nedarta/yii2-smart-cropper):

Copy

Simply copies the source image:

Dependency Pipeline

Create variants from other variants for optimized processing:

Benefits:

Advanced Examples

Blog Post with Multiple Variants

Product Image with Watermark Pipeline

User Avatar

Displaying Images

In Views

Helper Method

Add to your model:

File Structure Example

After uploading with variants, your directory will look like:

How It Works

Event Flow

  1. Before Validation - Captures the uploaded file
  2. After Insert/Update - Processes the upload:
    • Creates upload directories if needed
    • Removes old variants if updating
    • Saves uploaded file to temporary location
    • Applies EXIF auto-rotation
    • Converts format if forceConvert is set
    • Generates all variants in dependency order
    • Updates model with new filename
  3. Before Delete - Removes all variants

Variant Processing Pipeline

  1. Determine source for each variant (original or another variant)
  2. Process variants in order
  3. Apply transformation (resize/thumbnail/smartcrop/copy)
  4. Save with specified quality
  5. Use result as source for dependent variants

Troubleshooting

Images not rotating correctly

Variants not created

"Saving image in 'tmp' format is not supported"

Old images not deleted

License

Free to use and modify.

Credits

Created by nedarta


All versions of yii2-upload-behavior with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
yiisoft/yii2 Version ^2.0.52
yiisoft/yii2-imagine Version ^2.2
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 nedarta/yii2-upload-behavior contains the following files

Loading the files please wait ...