Download the PHP package yii2tech/file-storage without Composer

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

File Storage Extension for Yii 2


This extension provides file storage abstraction layer for Yii2.

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 Amazon S3 storage, you should also install aws/aws-sdk-php version 2. Either run

or add

to the require section of your composer.json.

If you wish to use MongoDB storage, you should also install yiisoft/yii2-mongodb version 2.1. Either run

or add

to the require section of your composer.json.

Usage

This extension provides file storage abstraction layer for Yii2. This abstraction introduces 2 main terms: 'storage' and 'bucket'. 'Storage' - is a unit, which is able to store files using some particular approach. 'Bucket' - is a logical part of the storage, which has own specific attributes and serves some logical mean. Each time you need to read/write a file you should do it via particular bucket, which is always belongs to the file storage.

Example application configuration:

Example usage:

Following file storages are available with this extension:

Please refer to the particular storage class for more details.

Heads up! Some of the storages may require additional libraries or PHP extensions, which are not required with this package by default, to be installed. Please check particular storage class documentation for the details.

Abstraction usage

Each provided storage implements same interface for the files processing. Thus each storage can substitute another one, unless program code follows this interface. This allows you to switch between different storages without being need to adjust program source code. For example, at production server you may need to use SFTP for files storing and your application config looks like following:

However, at development environment you may use simple local file storage instead:

You can also combine several different storages using [[\yii2tech\filestorage\hub\Storage]], if necessary:

Accessing files by URL

Almost all file storage implementation, implemented in this extension, provide mechanism for accessing stored files via web URL. Actual mechanism implementation may vary depending on particular storage. For example: [[\yii2tech\filestorage\local\Storage]] allows setup of the URL leading to its root folder, creating URL for particular file appending its name to base URL, while [[\yii2tech\filestorage\amazon\Storage]] uses S3 built-in object URL composition.

In order to get URL leading to the stored file, you should use [[\yii2tech\filestorage\BucketInterface::getFileUrl()]] method:

In case particular storage does not provide native URL file access, or it is not available or not desirable by some reason, you can setup composition of the file URL via Yii URL route mechanism. You need to setup baseUrl to be an array, containing route, which leads to the Yii controller action, which will return the file content. For example:

With this configuration getFileUrl() method will use current application URL manager to create URL. Doing so it will add bucket name as bucket parameter and file name as filename parameter. For example:

You may setup [[\yii2tech\filestorage\DownloadAction]] to handle file content web access. For example:

Tip: usage of the controller action for the file web access usually slower then native mechanism provided by file storage, however, you may put some extra logic into it, like allowing file access for logged in users only.

Processing of the large files

Saving or reading large files, like > 100 MB, using such methods like [[\yii2tech\filestorage\BucketInterface::saveFileContent()]] or [[\yii2tech\filestorage\BucketInterface::getFileContent()]], may easily exceed PHP memory limit, breaking the script. You should use [[\yii2tech\filestorage\BucketInterface::openFile()]] method to create a file resource similar to the one created via [[fopen()]] PHP function. Such resource can be read or written by blocks, keeping memory usage low. For example:

Note: You should prefer usage of simple modes like r and w, avoiding complex ones like w+, as they may be not supported by some storages.

Logging

Each file operation performed by file storage component is logged. In order to setup a log target, which can capture all entries related to file storage, you should use category yii2tech\filestorage\*. For example:


All versions of file-storage with dependencies

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

Loading the files please wait ....