{"id":14966675,"url":"https://github.com/itstructure/yii2-multi-format-uploader","last_synced_at":"2025-07-21T00:33:26.981Z","repository":{"id":56994561,"uuid":"133465803","full_name":"itstructure/yii2-multi-format-uploader","owner":"itstructure","description":"Module for Yii2 Framework to upload some type of files to local or S3 Amazon storage","archived":false,"fork":false,"pushed_at":"2023-01-23T00:00:48.000Z","size":372,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-15T12:45:20.923Z","etag":null,"topics":["amazon","file","internal-albums","module","s3-amazon-storage","upload","yii2","yii2-framework","yii2-template"],"latest_commit_sha":null,"homepage":"https://pack-develop.info/en/product/yii2-multi-format-uploader","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itstructure.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-15T05:53:32.000Z","updated_at":"2023-03-05T13:20:02.000Z","dependencies_parsed_at":"2023-02-12T15:16:46.990Z","dependency_job_id":null,"html_url":"https://github.com/itstructure/yii2-multi-format-uploader","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/itstructure/yii2-multi-format-uploader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-multi-format-uploader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-multi-format-uploader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-multi-format-uploader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-multi-format-uploader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itstructure","download_url":"https://codeload.github.com/itstructure/yii2-multi-format-uploader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itstructure%2Fyii2-multi-format-uploader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266221359,"owners_count":23894966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon","file","internal-albums","module","s3-amazon-storage","upload","yii2","yii2-framework","yii2-template"],"created_at":"2024-09-24T13:36:47.191Z","updated_at":"2025-07-21T00:33:26.725Z","avatar_url":"https://github.com/itstructure.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Yii2 Multi format uploader module - MFUploader\n==============\n\n## Introduction\n\n[![Latest Stable Version](https://poser.pugx.org/itstructure/yii2-multi-format-uploader/v/stable)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)\n[![Latest Unstable Version](https://poser.pugx.org/itstructure/yii2-multi-format-uploader/v/unstable)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)\n[![License](https://poser.pugx.org/itstructure/yii2-multi-format-uploader/license)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)\n[![Total Downloads](https://poser.pugx.org/itstructure/yii2-multi-format-uploader/downloads)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)\n[![Build Status](https://scrutinizer-ci.com/g/itstructure/yii2-multi-format-uploader/badges/build.png?b=master)](https://scrutinizer-ci.com/g/itstructure/yii2-multi-format-uploader/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/itstructure/yii2-multi-format-uploader/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/itstructure/yii2-multi-format-uploader/?branch=master)\n\n**MFUploader** -- Module for the Yii2 Framework to upload some type of files to local or S3 Amazon storage.\nMFUploader module provides the following options:\n- Upload files to local storage.\n- Upload files to remote Amazon S3 storage.\n- Support file formats: **image**, **audio**, **video**, **application**, **text**.\n- Link uploaded files with external application owners (pages, articles, posts e.t.c...).\n- Manage internal albums: **imageAlbum**, **audioAlbum**, **videoAlbum**, **applicationAlbum**, **textAlbum**, **otherAlbum**.\n- Link uploaded files with internal albums (owners).\n- Link internal albums with the external owners (pages, articles, posts e.t.c...).\n\nTo work with image binary content it uses [Yii2 imagine](https://github.com/yiisoft/yii2-imagine).\nTo work with Amazon it uses [AWS SDK](https://github.com/aws/aws-sdk-php).\n\nBase project examples, which use this MFUploader module:\n\n[yii2-template-multilanguage](https://github.com/itstructure/yii2-template-multilanguage).\n\n[yii2-template-simple](https://github.com/itstructure/yii2-template-simple).\n\nAddition module description you can see in my [Personal site](https://pack-develop.info/en/product/yii2-multi-format-uploader).\n\n## Requirements\n\n- php \u003e= 7.1\n- composer\n- MySql \u003e= 5.5\n- One of the next php extensions: GD|Imagick|Gmagick\n\n## Installation\n\n### Base install\n\nVia composer:\n\n`composer require itstructure/yii2-multi-format-uploader ~3.2.7`\n\n### If you are testing this package from local server directory\n\nIn application `composer.json` file set the repository, like in example:\n\n```json\n\"repositories\": [\n    {\n        \"type\": \"path\",\n        \"url\": \"../yii2-multi-format-uploader\",\n        \"options\": {\n            \"symlink\": true\n        }\n    }\n],\n```\n\nHere,\n\n**yii2-multi-format-uploader** - directory name, which has the same directory level like application and contains yii2 multi format uploader package.\n\nThen run command:\n\n`composer require itstructure/yii2-multi-format-uploader:dev-master --prefer-source`\n\n### Apply module migrations\n\nFor that make next, **if not already done**:\n    \n- Define **mfuploader** module in application **console** config file:\n\n    ```php\n    use Itstructure\\MFUploader\\Module as MFUModule;\n    ```\n    \n    ```php\n    'modules' =\u003e [\n        'mfuploader' =\u003e [\n            'class' =\u003e MFUModule::class,\n        ],\n    ],\n    ```\n\n- In file **yii**, that is located in application root directory, set **@mfuploader** alias:\n\n    ```php\n    $application = new yii\\console\\Application($config);\n    \n    \\Yii::setAlias('@mfuploader', $application-\u003egetModule('mfuploader')-\u003egetBasePath());\n    \n    $exitCode = $application-\u003erun();\n    ```\n    \n    OR\n    \n    ```php\n    use Itstructure\\MFUploader\\Module as MFUModule;\n    ```\n    \n    ```php\n    $application = new yii\\console\\Application($config);\n    \n    \\Yii::setAlias('@mfuploader', MFUModule::getBaseDir());\n    \n    $exitCode = $application-\u003erun();\n    ```\n    \n- Run command in console:\n\n    `yii migrate --migrationPath=@mfuploader/migrations`\n    \n    The data base structure:\n    \n    ![Data base structure](https://github.com/itstructure/yii2-multi-format-uploader/blob/master/db_structure.jpg)\n\n## Usage\n\n### Main properties\n\nThe **name** of module: `mfuploader`\n\nThe **namespace** for used classes: `Itstructure\\MFUploader`.\n\nThe **alias** to access in to module root directory: `@mfuploader`.\n\n### Application config\n\nBase application config must be like in example below:\n\n```php\nuse Itstructure\\MFUploader\\Module as MFUModule;\nuse Itstructure\\MFUploader\\controllers\\ManagerController;\nuse Itstructure\\MFUploader\\controllers\\upload\\{\n    LocalUploadController,\n    S3UploadController\n};\nuse Itstructure\\MFUploader\\controllers\\album\\{\n    ImageAlbumController,\n    AudioAlbumController,\n    VideoAlbumController,\n    ApplicationAlbumController,\n    TextAlbumController,\n    OtherAlbumController\n};\nuse Itstructure\\MFUploader\\components\\{\n    LocalUploadComponent,\n    S3UploadComponent\n};\n```\n\n```php\n'modules' =\u003e [\n    'mfuploader' =\u003e [\n        'class' =\u003e MFUModule::class, // REQUIRED\n        'layout' =\u003e ...path to layout..., // NOT REQUIRED\n        'view' =\u003e ...view component config..., // NOT REQUIRED\n        'controllerMap' =\u003e [ // CUSTOM\n            'upload/local-upload' =\u003e LocalUploadController::class,\n            'upload/s3-upload' =\u003e S3UploadController::class,\n            'managers' =\u003e ManagerController::class,\n            'image-album' =\u003e ImageAlbumController::class,\n            'audio-album' =\u003e AudioAlbumController::class,\n            'video-album' =\u003e VideoAlbumController::class,\n            'application-album' =\u003e ApplicationAlbumController::class,\n            'text-album' =\u003e TextAlbumController::class,\n            'other-album' =\u003e OtherAlbumController::class,\n        ],\n        'accessRoles' =\u003e ['admin', 'manager', e.t.c...], // CUSTOM\n        'defaultStorageType' =\u003e MFUModule::STORAGE_TYPE_S3, // CUSTOM\n        'components' =\u003e [ // CUSTOM\n            'local-upload-component' =\u003e [ // CUSTOM\n                'class' =\u003e LocalUploadComponent::class,\n                'checkExtensionByMimeType' =\u003e false,\n                'uploadRoot' =\u003e dirname($_SERVER['SCRIPT_FILENAME'])\n            ],\n            's3-upload-component' =\u003e [ // CUSTOM\n                'class' =\u003e S3UploadComponent::class,\n                'checkExtensionByMimeType' =\u003e false,\n                'credentials' =\u003e require __DIR__ . '/aws-credentials.php',\n                'region' =\u003e 'us-west-2',\n                's3DefaultBucket' =\u003e 'bucketname',\n            ],\n        ],\n        'publicBaseUrl' =\u003e 'http://your-site-address.com'\n    ],\n],\n```\n\nHere `publicBaseUrl` for example can be a project domain (`http://your-site-address.com`).\nIf we have `url` in `mediafiles` table `\\uploads\\images\\imagealbum\\0d\\3890\\a947f268d6f9fd02d8a0d7e147da922c.jpg`, and we use **getViewUrl()** function from a `mediafile` model for local files, \nthen for example a result link to image for `src` attribute of `\u003cimg\u003e` tag will be:\n\n`http://your-site-address.com/uploads/images/imagealbum/0d/3890/a947f268d6f9fd02d8a0d7e147da922c.jpg`\n\n**Note:** It is not necessary to configure two components: `local-upload-component` and `s3-upload-component`.\nYou must configure minimum one component, according with the `defaultStorageType`.\n\n### File field for the view template\n\n**File field** must be rendered by `FileSetter` widget.\n\nIt is necessary to send an ID or URL of uploaded mediafile to you application controller and set in \nmodel.\nAn after that to link mediafile ID with owner.\n\nExample (for image files):\n\n```php\nuse Itstructure\\MFUploader\\widgets\\FileSetter;\nuse Itstructure\\MFUploader\\Module as MFUModule;\nuse Itstructure\\MFUploader\\interfaces\\UploadModelInterface;\n```\n\n```html\nContainer to display selected image.\n\u003cdiv class=\"media\"\u003e\n    \u003cdiv id=\"mediafile-container\"\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"media-body\"\u003e\n        \u003ch4 id=\"title-container\" class=\"media-heading\"\u003e\u003c/h4\u003e\n        \u003cdiv id=\"description-container\"\u003e\u003c/div\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\n```php\necho FileSetter::widget([\n    'model' =\u003e $model,\n    'attribute' =\u003e UploadModelInterface::FILE_TYPE_IMAGE,\n    'neededFileType' =\u003e UploadModelInterface::FILE_TYPE_IMAGE,\n    'buttonName' =\u003e MFUModule::t('main', 'Set image'),\n    'options' =\u003e [\n        'id' =\u003e Html::getInputId($model, UploadModelInterface::FILE_TYPE_IMAGE)\n    ],\n    'mediafileContainer' =\u003e '#mediafile-container',\n    'titleContainer' =\u003e '#title-container',\n    'descriptionContainer' =\u003e '#description-container',\n    'owner' =\u003e 'post', // can be page, article, catalog e.t.c...\n    'ownerId' =\u003e {current owner id, post id, page id e.t.c.},\n    'ownerAttribute' =\u003e UploadModelInterface::FILE_TYPE_IMAGE,\n    'subDir' =\u003e 'post' // can be page, article, catalog e.t.c...\n]);\n```\n\n### Configure upload components\n\n#### Base attributes in BaseUploadComponent\n\n**Note:** BaseUploadComponent - the base class, which LocalUploadComponent and S3UploadComponent extend.\n\nTo understand the principles of configure the base attributes, see public attributes in `components\\BaseUploadComponent` class.\nBut it may be difficult to configure `thumbsConfig` and `thumbFilenameTemplate`.\nAttribute `thumbsConfig` takes the values according with the next chain:\n1. From the default config file `config/thumbs-config.php` in module **init()** function.\n2. Can be rewrited by custom during module `thumbsConfig` attribute.\n3. Previous config result inserted in to the `LocalUploadComponent` and `S3UploadComponent` module components.\n4. Configuration `thumbsConfig` in module components can be rewrited by custom during component `thumbsConfig` attribute.\n\n#### Attributes in LocalUploadComponent\n\nThat is very simple. See public attributes in `components\\LocalUploadComponent` class.\n\n#### Attributes in S3UploadComponent\n\nSee public attributes in `components\\S3UploadComponent` class.\nBut there are important attributes:\n- `credentials`. Attribute to access in to Amazon web services account.\n    Can be: array, callable, and other. See https://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html.\n- `s3DefaultBucket` - bucket, which you use to upload files as default.\n- `s3Buckets` - buckets to upload files depending on the owner. Not required.\n\n    config example:\n    ```php\n    's3Buckets' =\u003e [\n      'post' =\u003e 'bucketWithPosts',\n      'page' =\u003e 'bucketWithPages',\n      'imageAlbum' =\u003e 'bucketWithImages',\n      'audioAlbum' =\u003e 'bucketWithAudio',\n    ]\n    ```\n    \nFor more information of S3 configuration, see the next links:\n- https://docs.aws.amazon.com/aws-sdk-php/v3/guide/index.html\n- https://docs.aws.amazon.com/aws-sdk-php/v3/api\n- https://github.com/aws/aws-sdk-php\n\n### Link entities with owners\n\nTo link entities (mediafiles and albums) with owners (pages, articles, posts e.t.c...) there is the abstract class `behaviors\\Behavior`.\n\nYou must use child classes: `behaviors\\BehaviorMediafile` and `behaviors\\BehaviorAlbum`.\n\nExplanation by example.\n\nYou have a `catalog` model which extends an ActiveRecord yii2 class.\n\nUse a `behaviors\\BehaviorMediafile` and `behaviors\\BehaviorAlbum` in **behaviors** of your `catalog` model to link mediafiles and albums with catalog after: **insert active record**, **update active record**, **delete active record**:\n\n```php\nuse Itstructure\\MFUploader\\behaviors\\{BehaviorMediafile, BehaviorAlbum};\nuse Itstructure\\MFUploader\\interfaces\\UploadModelInterface;\nuse Itstructure\\MFUploader\\models\\album\\Album;\n```\n\n```php\npublic $thumbnail;\n\npublic $imageAlbum = [];\n\npublic function behaviors()\n{\n    return ArrayHelper::merge(parent::behaviors(), [\n        'mediafile' =\u003e [\n            'class' =\u003e BehaviorMediafile::class,\n            'name' =\u003e static::tableName(),\n            'attributes' =\u003e [\n                UploadModelInterface::FILE_TYPE_THUMB,\n            ],\n        ],\n        'albums' =\u003e [\n            'class' =\u003e BehaviorAlbum::class,\n            'name' =\u003e static::tableName(),\n            'attributes' =\u003e [\n                Album::ALBUM_TYPE_IMAGE,\n            ],\n        ],\n    ]);\n}\n```\n\n**Note:** This block should be used in conjunction with the `FileSetter` widget inside the view form template!\n\nHere the following happens:\n\n- If you use a \"thumbnail\" name of `attribute` param in FileSetter widget, the uploaded mediafile (thumbnail) will be linked with `catalog` after insert new catalog data to the data base.\n- If you use an \"imageAlbum\" (by Album::ALBUM_TYPE_IMAGE) name of the `name` attribute of dropdown or checkbox html field, the last created image album will be linked with `catalog` after insert new catalog data to the data base.\n\nThat works according with the next data base example structure:\n\n`Table \"mediafiles\"` - record with id=20 now inserted.\n\n    | id  | ... |      created_at     |      updated_at     |\n    |-----|-----|---------------------|---------------------|\n    | ... | ... |         ...         |         ...         |\n    | 20  | ... | 2018-05-06 21:35:04 | 2018-05-06 21:35:10 |\n\n`Table \"catalog\"` - record with id=10 inserted after create mediafile (id=20).\n\n    | id  | ... |      created_at     |      updated_at     |\n    |-----|-----|---------------------|---------------------|\n    | ... | ... |         ...         |         ...         |\n    | 10  | ... | 2018-05-06 21:35:20 | 2018-05-06 21:35:25 |\n\n`Table \"owners_mediafiles\"`\n\n    | mediafileId | ownerId |   owner   |  ownerAttribute  |\n    |-------------|---------|-----------|------------------|\n    |     ...     |   ...   |    ...    |        ...       |\n    |     20      |    10   |  catalog  |     thumbnail    |\n\n`Table \"albums\"`\n\n    | id  |     type    | ... |      created_at     |      updated_at     |\n    |-----|-------------|-----|---------------------|---------------------|\n    | ... |     ...     | ... |         ...         |         ...         |\n    |  5  | imageAlbum  | ... | 2018-05-06 21:30:00 | 2018-05-06 21:30:05 |\n\n`Table \"owners_albums\"`\n\n    | albumId | ownerId |   owner   |  ownerAttribute  |\n    |---------|---------|-----------|------------------|\n    |   ...   |   ...   |    ...    |        ...       |\n    |    5    |    10   |  catalog  |    imageAlbum    |\n\n**Note:** If you set in `FileSetter` widget the attributes: `owner`, `ownerId`, `ownerAttribute` - linking entity with owner will be done automatically during ajax request in **uploadmanager**.\n\n### Integrated album controllers\n\nThere are already integrated album controllers in the namespace: `Itstructure\\MFUploader\\controllers\\album`.\nControllers provide the work with the next types of albums: **imageAlbum**, **audioAlbum**, **videoAlbum**, **applicationAlbum**, **textAlbum**, **otherAlbum**.\n\nFor that controllers there are already the models and view templates.\n\nTo work with that, you must set just the routes in application configuration.\n\n## License\n\nCopyright © 2018-2023 Andrey Girnik girnikandrey@gmail.com.\n\nLicensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Fyii2-multi-format-uploader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitstructure%2Fyii2-multi-format-uploader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitstructure%2Fyii2-multi-format-uploader/lists"}