kriss/yii2-web-uploader

webuploader for Yii2 http://fex.baidu.com/webuploader/

Installs: 91

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 1

Open Issues: 0

Type:yii2-extension

v1.6 2020-05-19 14:08 UTC

This package is auto-updated.

Last update: 2024-10-20 00:33:23 UTC


README

webuploader for Yii2 http://fex.baidu.com/webuploader/

ScreenShot

Effect picture 1

Installation

composer require kriss/yii2-web-uploader

Usage

widgets

<?php
use \kriss\webUploader\widgets\QuickWebUploader;

echo QuickWebUploader::widget([
    'fileNumLimit' => 5,
]);
// or
echo $form->field($model, 'file')->widget(QuickWebUploader::class, [
    'uploadUrl' => ['/file/upload'],
]);
?>

actions

<?php

namespace admin\controllers;

use yii\web\Controller;
use kriss\webUploader\actions\QuickDeleteAction;
use kriss\webUploader\actions\QuickUploadAction;

class FileController extends Controller
{
    public function actions()
    {
        return [
            'upload' => [
                'class' => QuickUploadAction::class,
                'savePath' => '@webroot/uploads',
                'displayPath' => '@web/uploads',
            ],
            'delete' => [
                'class' => QuickDeleteAction::class,
                'savePath' => '@webroot/uploads',
                'displayPath' => '@web/uploads',
            ],
        ];
    }
}

examples

only accept images

<?php
// for client validate
// QuickWebUploader
[
    'pluginOptions' => [
        'accept' => [
            'extensions' => 'png,jpeg,jpg,gif',
            'mimeTypes' => 'image/*',
        ],
    ],
];

// for server validate
// QuickUploadAction
[
    'validationRules' => [
        ['file', 'file', 'extensions' => ['png', 'jpeg', 'jpg', 'gif'], 'mimeTypes' => 'image/*', 'maxSize' => 5*1024*1024]
    ],
];