Download the PHP package ptheofan/yii2-file-upload-behavior without Composer

On this page you can find all versions of the php package ptheofan/yii2-file-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-file-upload-behavior

Documentation is incomplete and will add more info and examples as time allows. Feel free to open an issue if there's something you want to ask or add to the documentation. Currently it comes with a facade for the FlySystem only. In due time I will add also a facade for basic local filesystem

The entire system is designed to be very customisable and extensible. There are a couple of points that can be (and will be) improved to make it as extensible and customisable as possible whilst keeping it sane.

This is an example of how to configure the behavior and use it to allow users to upload their avatar. In this example we want to achieve the following

  1. access the property as avatar
    1. see modelVirtualAttribute
  2. store the filename to the database in the column avatar_hash.
    1. see modelAttribute
  3. Filename prefixed with row ID, filename the SHA1 of the file and suffix the version
    1. For this we set the filenameGenerator to use the CallbackFilenameGenerator
    2. Configure it to not include the extension (versions will take care of .ext in this case)
  4. Keep the following versions
    1. Unresized upload in PNG format PngBaseVersion. Final name will look something like 512-deadbeef.png
    2. sm (width = 64 pixels) with suffix -sm. Final name will look something like 512-deadbeef-sm.png
    3. md (width = 256 pixels) with suffix -md. Final name will look something like 512-deadbeef-md.png
    4. lg (width = 512 pixels) with suffix -lg. Final name will look something like 512-deadbeef-lg.png

When the request arrives simply push the UploadedFile instance to the avatar model property, save the model and voila, image stored as per the provided configuration and all versions are generated.

When you want to retrieve a particular version of the uploaded file simply call

You can also print the object to get detailed helpful information

In the following example we configure our model to use the database column avatar_hash to store the file information in the database and set virtual attribute to avatar. This means

  1. $model->avatar_hash contains the value produced by the generator (you typically don't care to touch this column).
  2. $model->avatar is your accessor to the image. Calling $model->avatar->getVersion('sm')->getUrl() will return the complete URL to the small version of the file.
  3. You can assign an uploaded file as simple as $model->avatar = UploadedFile::getInstance($model, 'avatar')
  4. You can push a base64 encoded image as simply as $model->avatar = $myBase64EncodedImage
  5. You can push a binary string simply by $model->avatar = file_get_contents('my_file.png')

All versions of yii2-file-upload-behavior with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
ext-fileinfo Version *
yiisoft/yii2 Version ^2.0
ptheofan/yii2-image-helper Version ^1.0
ptheofan/yii2-file-helper Version ^1.0
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 ptheofan/yii2-file-upload-behavior contains the following files

Loading the files please wait ....