{"id":13411488,"url":"https://github.com/daxslab/yii2-uploader-behavior","last_synced_at":"2025-04-10T00:25:30.096Z","repository":{"id":56963711,"uuid":"86965345","full_name":"daxslab/yii2-uploader-behavior","owner":"daxslab","description":"Simplify the process to upload a file at model level","archived":false,"fork":false,"pushed_at":"2023-07-09T23:28:50.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T16:12:35.903Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/daxslab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-02T05:23:30.000Z","updated_at":"2023-07-09T23:23:26.000Z","dependencies_parsed_at":"2022-08-21T10:20:16.221Z","dependency_job_id":null,"html_url":"https://github.com/daxslab/yii2-uploader-behavior","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daxslab%2Fyii2-uploader-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daxslab%2Fyii2-uploader-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daxslab%2Fyii2-uploader-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daxslab%2Fyii2-uploader-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daxslab","download_url":"https://codeload.github.com/daxslab/yii2-uploader-behavior/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239088383,"owners_count":19579432,"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":[],"created_at":"2024-07-30T20:01:14.035Z","updated_at":"2025-02-16T04:32:38.819Z","avatar_url":"https://github.com/daxslab.png","language":"PHP","funding_links":[],"categories":["Web Development"],"sub_categories":["PHP"],"readme":"Yii2 Uploader Behavior for Active Record\n========================================\n\n[![Build Status](https://secure.travis-ci.org/daxslab/yii2-uploader-behavior.png)](http://travis-ci.org/daxslab/yii2-uploader-behavior)\n[![Latest Stable Version](https://poser.pugx.org/daxslab/yii2-uploader-behavior/v/stable.svg)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)\n[![Total Downloads](https://poser.pugx.org/daxslab/yii2-uploader-behavior/downloads)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)\n[![Latest Unstable Version](https://poser.pugx.org/daxslab/yii2-uploader-behavior/v/unstable.svg)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)\n[![License](https://poser.pugx.org/daxslab/yii2-uploader-behavior/license.svg)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)\n\nAutomates file uploading for every attribute tagged with `file` or `image` validation rule. It also configures the way that filename should be renamed and stored in database as attribute value.\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist daxslab/yii2-uploader-behavior \"*\"\n```\n\nor add\n\n```\n\"daxslab/yii2-uploader-behavior\": \"*\"\n```\n\nto the require section of your `composer.json` file.\n\n\nUsage\n-----\n\nOnce the extension is installed, simply use it in your models by  :\n\n```php\nuse daxslab/behaviors/UploaderBehavior;\n\npublic function behaviors() {\n    return [\n        UploaderBehavior::className()\n    ];\n}\n```\n\nThis is the simplest way of usage. It will look for all attributes with a `file` or `image` validation rule.\n\n```php\npublic function rules()\n{\n    return [\n        [['name'], 'required'],\n        [['name'], 'string', 'max' =\u003e 256],\n        [['image'], 'image', 'skipOnEmpty' =\u003e true],\n    ];\n}\n```\n\nAnd update the form to specify a file input for the image attribute:\n\n```php\n$form-\u003efield($model, 'image')-\u003efileInput();\n```\n\nFor a more controlled usage, you can specify which attributes to control using the `attributes` option as in  :\n\n```php\nuse daxslab/behaviors/UploaderBehavior;\n\npublic function behaviors() {\n    return [\n        [\n            'class' =\u003e UploaderBehavior::className(),\n            'attributes' =\u003e ['avatar'] // or you can use the string format as in 'attributes' =\u003e 'avatar'\n        ]\n    ];\n}\n```\n\nBy default the filename of the uploaded file is randomized, but if you want to configure it you can setup the `renamer`\noption:\n\n```php\nuse daxslab/behaviors/UploaderBehavior;\n\npublic function behaviors() {\n    return [\n        [\n            'class' =\u003e UploaderBehavior::className(),\n            'attributes' =\u003e ['avatar'] // or you can use the string format as in 'attributes' =\u003e 'avatar'\n            'renamer' =\u003e UploaderBehavior::RENAME_MD5 //will encode the filename with md5()\n        ]\n    ];\n}\n```\n\nalso you can specify a custom function to rename the filename:\n\n```php\nuse daxslab/behaviors/UploaderBehavior;\n\npublic function behaviors() {\n    return [\n        [\n            'class' =\u003e UploaderBehavior::className(),\n            'attributes' =\u003e ['avatar'] // or you can use the string format as in 'attributes' =\u003e 'avatar'\n            'renamer' =\u003e function($name, $owner){\n                return strtoupper($name); //will turn the filename into uppercase\n            }\n        ]\n    ];\n}\n```\n\nProudly made by [Daxslab](http://daxslab.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaxslab%2Fyii2-uploader-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaxslab%2Fyii2-uploader-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaxslab%2Fyii2-uploader-behavior/lists"}