{"id":20160351,"url":"https://github.com/kriptograf/yii2-upload-behavior","last_synced_at":"2025-10-10T17:04:48.765Z","repository":{"id":57009204,"uuid":"231944374","full_name":"kriptograf/yii2-upload-behavior","owner":"kriptograf","description":"This package is the set of two similar behaviors. The first one allows you to keep the uploaded file as-is.  And the second one allows you to generate set of thumbnails for the uploaded image. Behaviors could be attached  multiple times for different attributes.","archived":false,"fork":false,"pushed_at":"2020-01-05T18:10:30.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T17:03:07.846Z","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/kriptograf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-05T16:23:37.000Z","updated_at":"2020-01-05T18:10:32.000Z","dependencies_parsed_at":"2022-08-21T14:50:52.212Z","dependency_job_id":null,"html_url":"https://github.com/kriptograf/yii2-upload-behavior","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kriptograf/yii2-upload-behavior","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriptograf%2Fyii2-upload-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriptograf%2Fyii2-upload-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriptograf%2Fyii2-upload-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriptograf%2Fyii2-upload-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kriptograf","download_url":"https://codeload.github.com/kriptograf/yii2-upload-behavior/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kriptograf%2Fyii2-upload-behavior/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004814,"owners_count":26083783,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-14T00:13:40.063Z","updated_at":"2025-10-10T17:04:48.715Z","avatar_url":"https://github.com/kriptograf.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 file/image upload behavior for ActiveRecord #\n \nThis package is the set of two similar behaviors. The first one allows you to keep the uploaded file as-is.\n And the second one allows you to generate set of thumbnails for the uploaded image. Behaviors could be attached\n multiple times for different attributes.\n \n## Installation ##\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n    composer require --prefer-dist kriptograf/yii2-upload-behavior\n\nor add\n\n    \"kriptograf/yii2-upload-behavior\": \"*\"\n\nto the `require` section of your composer.json.\n \n## FileUploadBehavior ##\n\nThis behavior allow you to add file uploading logic with ActiveRecord behavior.\n\n### Usage ###\nAttach the behavior to your model class:\n\n    public function behaviors()\n    {\n        return [\n            [\n                'class' =\u003e '\\kriptograf\\upload\\FileUploadBehavior',\n                'attribute' =\u003e 'fileUpload',\n                'filePath' =\u003e '@webroot/uploads/[[pk]].[[extension]]',\n                'fileUrl' =\u003e '/uploads/[[pk]].[[extension]]',\n            ],\n        ];\n    }\n   \nYou can use Yii path [aliases](http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html) \nlike `@app`, `@webroot`, `@web` in your path template configuration.\n\nYou can also use additional placeholders in path templates.\nPlaceholder `[[foobar]]` will be replaced with appropriate placeholder value. \n\nPossible path/url placeholders:\n\n * `[[model]]` - model class name\n * `[[pk]]` - value of the primary key \n * `[[id]]` - the same as `[[pk]]`\n * `[[attribute_name]]` - attribute value, for example `[[attribute_ownerId]]`\n * `[[id_path]]` - id subdirectories structure (if model primary key is `12345`, placeholder value will be `1/2/3/4/5/0/0/0/0/0`\n * `[[basename]]` - original filename with extension\n * `[[filename]]` - original filename without extension\n * `[[extension]]` - original extension\n    \nAdd validation rule:\n\n    public function rules()\n    {\n        return [\n            ['fileUpload', 'file'],   \n        ];\n    }\n\nSetup proper form enctype:\n\n    $form = \\yii\\bootstrap\\ActiveForm::begin([\n        'enableClientValidation' =\u003e false,\n        'options' =\u003e [\n            'enctype' =\u003e 'multipart/form-data',\n        ],\n    ]);\n\nFile should be uploading fine.\n\nYou can get uploaded file url using model call:\n\n    echo $model-\u003egetUploadedFileUrl('fileUpload');\n\n## ImageUploadBehavior ##\n\nImage upload behavior extends file upload behavior with image thumbnails generation.\nYou can configure set of different thumbnail profiles to generate.\n\n### Usage ###\nAttach the behavior to your model class:\n\n    public function behaviors()\n    {\n        return [\n            [\n                 'class' =\u003e '\\kriptograf\\upload\\ImageUploadBehavior',\n                 'attribute' =\u003e 'imageUpload',\n                 'thumbs' =\u003e [\n                     'thumb' =\u003e ['width' =\u003e 400, 'height' =\u003e 300],\n                 ],\n                 'filePath' =\u003e '@webroot/images/[[pk]].[[extension]]',\n                 'fileUrl' =\u003e '/images/[[pk]].[[extension]]',\n                 'thumbPath' =\u003e '@webroot/images/[[profile]]_[[pk]].[[extension]]',\n                 'thumbUrl' =\u003e '/images/[[profile]]_[[pk]].[[extension]]',\n            ],\n        ];\n    }\n\nYou can use Yii path [aliases](http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html) \nlike `@app`, `@webroot`, `@web` in your path template configuration.\n\nYou can also use additional placeholders in path templates.\nPlaceholder `[[foobar]]` will be replaced with appropriate placeholder value. \n\nPossible path/url placeholders:\n\n * `[[model]]` - model class name\n * `[[pk]]` - value of the primary key \n * `[[id]]` - the same as `[[pk]]`\n * `[[attribute_name]]` - attribute value, for example `[[attribute_ownerId]]`\n * `[[id_path]]` - id subdirectories structure (if model primary key is `12345`, placeholder value will be `1/2/3/4/5/0/0/0/0/0`\n * `[[basename]]` - original filename with extension\n * `[[filename]]` - original filename without extension\n * `[[extension]]` - original extension\n * `[[profile]]` - thumbnail profile name, use it in thumbnail path/url\n    \nAdd validation rule:\n\n    public function rules()\n    {\n        return [\n            ['imageUpload', 'file', 'extensions' =\u003e 'jpeg, gif, png'],   \n        ];\n    }\n\nSetup proper form enctype:\n\n    $form = \\yii\\bootstrap\\ActiveForm::begin([\n        'enableClientValidation' =\u003e false,\n        'options' =\u003e [\n            'enctype' =\u003e 'multipart/form-data',\n        ],\n    ]);\n\nFile should be uploading fine.\n\nYou can get uploaded image url using model call:\n\n    echo $model-\u003egetImageFileUrl('imageUpload');\n\nYou can specify default image for models without uploaded image:\n\n    echo $model-\u003egetImageFileUrl('imageUpload', '/images/empty.jpg');\n\nYou can also get generated thumbnail image url:\n\n    echo $model-\u003egetThumbFileUrl('imageUpload', 'thumb');\n\nYou can specify default thumbnail image for models without uploaded image:\n  \n    echo $model-\u003egetThumbFileUrl('imageUpload', 'thumb', '/images/thumb_empty.jpg');\n\n## Licence ##\n\nMIT\n    \n## Links ##\n\n* [Source code on GitHub](https://github.com/kriptograf/yii2-upload-behavior)\n* [Composer package on Packagist](https://packagist.org/packages/kriptograf/yii2-upload-behavior)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriptograf%2Fyii2-upload-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkriptograf%2Fyii2-upload-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkriptograf%2Fyii2-upload-behavior/lists"}