All Projects → 2amigos → Yii2 File Upload Widget

2amigos / Yii2 File Upload Widget

Licence: other
BlueImp File Upload Widget for Yii2

Projects that are alternatives of or similar to Yii2 File Upload Widget

Ajaxfileupload
A jQuery plugin that simulates asynchronous file uploads.
Stars: ✭ 291 (+15.94%)
Mutual labels:  file-upload, jquery
Cc
一个基于angular5.0.0+ng-bootstrap1.0.0-beta.8+bootstrap4.0.0-beta.2+scss的后台管理系统界面(没基础的同学请先自学基础,谢谢!)
Stars: ✭ 416 (+65.74%)
Mutual labels:  file-upload, jquery
Fileup
FileUp - JQuery File Upload
Stars: ✭ 10 (-96.02%)
Mutual labels:  file-upload, jquery
Jquery Multiselect
Turn a multiselect list into a nice and easy to use list with checkboxes.
Stars: ✭ 221 (-11.95%)
Mutual labels:  jquery
Bbs Ssm
南生论坛基于SSM框架,自适应手机端和电脑端,界面简洁美观,功能完善。演示地址:http://www.nanshengbbs.top
Stars: ✭ 221 (-11.95%)
Mutual labels:  jquery
Jquery Viewer
A jQuery plugin wrapper for Viewer.js.
Stars: ✭ 235 (-6.37%)
Mutual labels:  jquery
Visual Studio Jquery Code Snippets
130+ jQuery code snippets for Visual Studio 2012-2019.
Stars: ✭ 250 (-0.4%)
Mutual labels:  jquery
Jquery Selector Set
Stars: ✭ 219 (-12.75%)
Mutual labels:  jquery
Ziptastic Jquery Plugin
This is a jQuery plugin that shows how Ziptastic could be used.
Stars: ✭ 244 (-2.79%)
Mutual labels:  jquery
Liteaccordion
A lightweight horizontal accordion plugin for jQuery.
Stars: ✭ 234 (-6.77%)
Mutual labels:  jquery
Jqwidgets
Angular, Vue, React, Web Components, Blazor, Javascript, jQuery and ASP .NET Framework,
Stars: ✭ 227 (-9.56%)
Mutual labels:  jquery
Telegram Upload
Upload and download files from Telegram up to 2GiB using your account
Stars: ✭ 223 (-11.16%)
Mutual labels:  file-upload
Yii2 Apidoc
Yii 2 apidoc extension.
Stars: ✭ 236 (-5.98%)
Mutual labels:  yii
Yii2 Framework
[READ ONLY] Yii 2 framework core code only. This is a subtree split off the "yii2" repository
Stars: ✭ 221 (-11.95%)
Mutual labels:  yii
Django Bootstrap Modal Forms
A Django plugin for creating AJAX driven forms in Bootstrap modal.
Stars: ✭ 244 (-2.79%)
Mutual labels:  jquery
Ngx File Drop
Angular 11 file and folder drop library
Stars: ✭ 220 (-12.35%)
Mutual labels:  file-upload
Ajax Live Search
AJAX Live Search is a PHP search form that similar to Google Autocomplete feature displays the result as you type.
Stars: ✭ 238 (-5.18%)
Mutual labels:  jquery
Jquery Auto Geocoder
jQuery plug-in to automatically geocode and display a location entered.
Stars: ✭ 227 (-9.56%)
Mutual labels:  jquery
Tablesorter
Github fork of Christian Bach's tablesorter plugin + awesomeness ~
Stars: ✭ 2,532 (+908.76%)
Mutual labels:  jquery
Warehouse Inventory System
Open source inventory management system with php and mysql
Stars: ✭ 235 (-6.37%)
Mutual labels:  jquery

BlueImp File Upload Widget for Yii2

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Renders a BlueImp jQuery File Upload plugin. That plugin integrates multiple file selection, drag&drop support, progress bars, validation and preview of images.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require 2amigos/yii2-file-upload-widget:~1.0

or add

"2amigos/yii2-file-upload-widget": "~1.0"

to the require section of your composer.json file.

Usage

The widget comes with two flavors:

<?php
use dosamigos\fileupload\FileUpload;

// without UI
?>

<?= FileUpload::widget([
    'model' => $model,
    'attribute' => 'image',
    'url' => ['media/upload', 'id' => $model->id], // your url, this is just for demo purposes,
    'options' => ['accept' => 'image/*'],
    'clientOptions' => [
        'maxFileSize' => 2000000
    ],
    // Also, you can specify jQuery-File-Upload events
    // see: https://github.com/blueimp/jQuery-File-Upload/wiki/Options#processing-callback-options
    'clientEvents' => [
        'fileuploaddone' => 'function(e, data) {
                                console.log(e);
                                console.log(data);
                            }',
        'fileuploadfail' => 'function(e, data) {
                                console.log(e);
                                console.log(data);
                            }',
    ],
]); ?>

<?php
use dosamigos\fileupload\FileUploadUI;

// with UI
?>
<?= FileUploadUI::widget([
    'model' => $model,
    'attribute' => 'image',
    'url' => ['media/upload', 'id' => $tour_id],
    'gallery' => false,
    'fieldOptions' => [
        'accept' => 'image/*'
    ],
    'clientOptions' => [
        'maxFileSize' => 2000000
    ],
    // ...
    'clientEvents' => [
        'fileuploaddone' => 'function(e, data) {
                                console.log(e);
                                console.log(data);
                            }',
        'fileuploadfail' => 'function(e, data) {
                                console.log(e);
                                console.log(data);
                            }',
    ],
]); ?>

<?php

// action examples

public function actionImageUpload()
{
    $model = new WhateverYourModel();

    $imageFile = UploadedFile::getInstance($model, 'image');

    $directory = Yii::getAlias('@frontend/web/img/temp') . DIRECTORY_SEPARATOR . Yii::$app->session->id . DIRECTORY_SEPARATOR;
    if (!is_dir($directory)) {
        FileHelper::createDirectory($directory);
    }

    if ($imageFile) {
        $uid = uniqid(time(), true);
        $fileName = $uid . '.' . $imageFile->extension;
        $filePath = $directory . $fileName;
        if ($imageFile->saveAs($filePath)) {
            $path = '/img/temp/' . Yii::$app->session->id . DIRECTORY_SEPARATOR . $fileName;
            return Json::encode([
                'files' => [
                    [
                        'name' => $fileName,
                        'size' => $imageFile->size,
                        'url' => $path,
                        'thumbnailUrl' => $path,
                        'deleteUrl' => 'image-delete?name=' . $fileName,
                        'deleteType' => 'POST',
                    ],
                ],
            ]);
        }
    }

    return '';
}

public function actionImageDelete($name)
{
    $directory = Yii::getAlias('@frontend/web/img/temp') . DIRECTORY_SEPARATOR . Yii::$app->session->id;
    if (is_file($directory . DIRECTORY_SEPARATOR . $name)) {
        unlink($directory . DIRECTORY_SEPARATOR . $name);
    }

    $files = FileHelper::findFiles($directory);
    $output = [];
    foreach ($files as $file) {
        $fileName = basename($file);
        $path = '/img/temp/' . Yii::$app->session->id . DIRECTORY_SEPARATOR . $fileName;
        $output['files'][] = [
            'name' => $fileName,
            'size' => filesize($file),
            'url' => $path,
            'thumbnailUrl' => $path,
            'deleteUrl' => 'image-delete?name=' . $fileName,
            'deleteType' => 'POST',
        ];
    }
    return Json::encode($output);
}

Please, check the jQuery File Upload documentation for further information about its configuration options.

Using the Actions

TODO

Testing

$ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The BSD License (BSD). Please see License File for more information.


web development has never been so fun
www.2amigos.us
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].