定制 exocet/yii2-upload-file-behavior 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

exocet/yii2-upload-file-behavior

最新稳定版本:1.0.0

Composer 安装命令:

composer require exocet/yii2-upload-file-behavior

包简介

A Yii2 behavior designed to simplify the process of uploading and managing files and images associated with ActiveRecord models.

README 文档

README

UploadFileBehavior is a Yii2 behavior designed to streamline the process of uploading files and/or images. It manages the processing and storage of files associated with an ActiveRecord model.

Features

  • File uploading for ActiveRecord models.
  • Customizable file saving steps.
  • Thumbnail generation.
  • Option to rename uploaded files.
  • Ability to delete files when associated records are deleted.
  • Automatic cleanup of directories during updates.

Installation

The preferred way to install this extension is through composer.

composer require "exocet/yii2-upload-file-behavior"

Setup and Configuration

  1. Include new behavior:

    use exocet\yii2UploadFileBehavior\UploadFileBehavior;
  2. Add the upload file attribute to your model:

    public $upload_file;
  3. Add safety rules for your image path or similar:

    [['image_path'], 'safe'],
  4. Attach the behavior to your model:

    public function behaviors() {
        return [
            'uploadFileBehavior' => [
                'class' => UploadFileBehavior::className(),
                'nameOfAttributeStorage' => 'image_path',
                //... other configurations
            ],
        ];
    }

Configuration Options

Here's a quick run-through of the configuration options:

  • modelAttributeForFile: (string) The model's attribute to receive the file from the form. Defaults to 'upload_file'.

  • modelAttributeForStorage: (string) The model's attribute to store the file path or reference. Defaults to 'images'.

  • newFileName: (bool|string) A new filename to save the uploaded file as. Defaults to false (meaning it won't rename).

  • steps: (array) Configurations detailing where and how to save the uploaded file. This can include thumbnail generation, different save paths, etc.

  • thumbnailPrefix: (string) Prefix for generated thumbnails. Defaults to 'thumb-'.

  • originalPrefix: (string) Prefix to use when saving a copy of the original image. Defaults to 'original-'.

  • scenarios: (array) Scenarios under which this behavior will be triggered. Defaults to ['default'].

  • deleteImageWithRecord: (bool) Whether or not to delete the file when the associated record is deleted. Defaults to false.

  • cleanDirWithUpdate: (bool) Whether or not to clean the upload directory when updating files. Defaults to false.

For more in-depth examples and how to set up the steps configuration, refer to the example given in the code comments.

Contribution

Feel free to contribute to this project by opening issues, pull requests, or providing feedback. Your contributions are welcome!

Designed with ❤️ for Yii2 developers.

统计信息

  • 总下载量: 37
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-20