定制 hossein142001/yii2-my-image-validator 二次开发

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

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

hossein142001/yii2-my-image-validator

Composer 安装命令:

composer require hossein142001/yii2-my-image-validator

包简介

Yii2 extension to help in the image validator for ratio and resolution

README 文档

README

Yii2 extension to help in the creation of automated console scripts. It helps to manage the execution of console scripts, for example avoiding the execution if the previous cron is already running. It generates a history of cron executed, with the time spent and helps to batch processing the script.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist hossein142001/yii2-my-image-validator "*"

or add

"hossein142001/yii2-my-image-validator": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, you can use it as a helper in your console controller.

See the following example:

<?php
namespace somenamespace\controllers;

use hossein142001\MyImageValidator\models\MyImageValidator;
use somenamespace\SomeModel;
use yii\console\Controller;

/**
 * SomeContrController controller
 */
class SomeContrController extends Controller {
 
    /**
     * @SWG\Post(
     *     path="/v1/files/upload",
     *     tags={"files"},
     *     summary="Create",
     *     description="create *query* *formData*  post",
     *     produces={"application/json"},
     *     @SWG\Parameter(
     *       in = "formData",
     *       name = "files",
     *       description = "rollcalls",
     *       required = true,
     *       type = "file",
     *     ),
     *     @SWG\Response(
     *         response = 200,
     *         description = " success"
     *     ),
     *     @SWG\Response(
     *         response = 401,
     *         description = "Error in Create",
     *         @SWG\Schema(ref="#/definitions/Error")
     *     )
     * )
     *
     */
    public function actionUpload()
    {
        $model = new File();

        $model = DynamicModel::validateData(['files'], [
            [['files'], MyImageValidator::className(), 'skipOnEmpty' => false, 'maxFiles' => 10,'ratio'=>3/4,'resolution' => 700, 'maxWidth' => 250,'minHeight' => 250, 'maxHeight' => 250, 'extensions' => 'jpg']
        ]);

        if (Yii::$app->request->isPost) {
            $model->files = UploadedFile::getInstancesByName('files');
            if ($model->validate()) {
                $data = [
                    'path' => 'files',
                    'context' => '025',
                    'version' => '1',
                    'metadata' => ['meta' => 1, 'meta2' => 2, 'meta3' => 3],
                ];
                return FlysystemWrapper::upload($model->files, $data);
            }
            return $model;
        }

        return $model;
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-02