Download the PHP package yii2tech/ar-file without Composer

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

ActiveRecord File Attachment Extension for Yii2


This extension provides support for ActiveRecord file attachment.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

If you wish to use [[yii2tech\ar\file\ImageFileBehavior]], you will also need to install yiisoft/yii2-imagine, which is not required by default. In order to do so either run

or add

to the require section of your composer.json.

Usage

This extension provides support for ActiveRecord file attachment. Attached files are stored inside separated file storage, which does not connected with ActiveRecord database.

This extension based on yii2tech/file-storage, and uses it as a file saving layer. Thus attached files can be stored at any file storage such as local file system, Amazon S3 and so on.

First of all, you need to configure file storage, which will be used for attached files:

You should use [[\yii2tech\ar\file\FileBehavior]] behavior in order to allow your ActiveRecord file saving. This can be done in following way:

Usage of this behavior requires extra columns being present at the owner entity (database table):

For example, DDL for the 'item' table may look like following:

Once behavior is attached to may use saveFile() method on your ActiveRecord instance:

This method will save source file inside file storage bucket, which has been specified inside behavior configuration, and update file extension and version attributes.

You may delete existing file using deleteFile() method:

Note: attached file will be automatically removed on owner deletion (delete() method invocation).

You may check existence of the file, get its content or URL:

Tip: you may setup [[\yii2tech\ar\file\FileBehavior::defaultFileUrl]] in order to make getFileUrl() returning some default image URL in case actual attached file is missing.

Working with web forms

Usually files for ActiveRecord are setup via web interface using file upload mechanism. [[\yii2tech\ar\file\FileBehavior]] provides a special virtual property for the owner, which name is determined by [[\yii2tech\ar\file\FileBehavior::fileAttribute]]. This property can be used to pass [[\yii\web\UploadedFile]] instance or local file name, which should be attached to the ActiveRecord. This property is processed on owner saving, and if set will trigger file saving. For example:

Attention: do NOT declare [[\yii2tech\ar\file\FileBehavior::fileAttribute]] attribute in the owner ActiveRecord class. Make sure it does not conflict with any existing owner field or virtual property.

If [[\yii2tech\ar\file\FileBehavior::autoFetchUploadedFile]] is enabled, behavior will attempt to fetch uploaded file automatically before owner saving.

You may setup a validation rules for the file virtual attribute inside your model, specifying restrictions for the attached file type, extension and so on:

Inside view file you can use file virtual property for the form file input as it belongs to the owner model itself:

Inside the controller you don't need any special code:

File transformation

Saving file "as it is" is not always enough for ActiveRecord attachment. Often files require some processing, like image resizing, for example.

[[\yii2tech\ar\file\TransformFileBehavior]] is an enhanced version of the [[FileBehavior]] developed for the managing files, which require some processing (transformations). You should setup [[\yii2tech\ar\file\TransformFileBehavior::transformCallback]] to specify actual file processing algorithm, and [[\yii2tech\ar\file\TransformFileBehavior::fileTransformations]] providing the list of named processing and their specific settings. For example:

In case of usage [[\yii2tech\ar\file\TransformFileBehavior]] methods fileExists(), getFileContent() and getFileUrl() accepts first parameter as a transformation name, for which result should be returned:

Some file transformations may require changing the file extension. For example: you may want to create a preview for the .psd file in .jpg format. You may specify file extension per each transformation using [[\yii2tech\ar\file\TransformFileBehavior::transformationFileExtensions]]. For example:

You may face the issue, when settings for some file transformations change or new transformation added, as your project evolves, making existing saved files outdated. In this case you can use [[\yii2tech\ar\file\TransformFileBehavior::regenerateFileTransformations()]] method to regenerate transformation files with new settings using some existing transformation as source. For example:

Image file transformation

The most common file transformation use case is an image resizing. Thus a special behavior [[\yii2tech\ar\file\ImageFileBehavior]] is provided. This behavior provides image resize transformation via yiisoft/yii2-imagine extension. Configuration example:

Note: this package does not include "yiisoft/yii2-imagine", you should install it yourself.


All versions of ar-file with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
yii2tech/file-storage 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 yii2tech/ar-file contains the following files

Loading the files please wait ....