Git Product home page Git Product logo

yii2-dropzone's Introduction

Yii2 Dropzone

DropzoneJs Extention for Yii2

A port of DropzoneJs for Yii2 Framework

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist perminder-klair/yii2-dropzone "dev-master"

or add

"perminder-klair/yii2-dropzone": "dev-master"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by to create Ajax upload area :

echo \kato\DropZone::widget();

To pass options : (More details at dropzonejs official docs )

echo \kato\DropZone::widget([
       'options' => [
           'maxFilesize' => '2',
       ],
       'clientEvents' => [
           'complete' => "function(file){console.log(file)}",
           'removedfile' => "function(file){alert(file.name + ' is removed')}"
       ],
   ]);

Example of upload method :

public function actionUpload()
{
    $fileName = 'file';
    $uploadPath = './files';

    if (isset($_FILES[$fileName])) {
        $file = \yii\web\UploadedFile::getInstanceByName($fileName);

        //Print file data
        //print_r($file);

        if ($file->saveAs($uploadPath . '/' . $file->name)) {
            //Now save file data to database

            echo \yii\helpers\Json::encode($file);
        }
    }

    return false;
}

yii2-dropzone's People

Contributors

evgen-d avatar niekoost avatar perminder-klair avatar robertklein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-dropzone's Issues

Validate with Yii2 Model

How can i validate yii2-dropzone with Yii2 Model, if i require aleast 1 or 2 pics to be uploaded and it gives error that pics are required to be uploaded. like we do in text box validation.

Get mapping error with github repo.

Hello there,

I have used this widget in my app and its working fine in my local system. but while i push whole code in github repository at that time yii2-dropzone folders/files not uploaded in my repository and getting below error on docker,
No submodule mapping found in .gitmodules for path 'vendor/perminder-klair/yii2-dropzone'
Can you please help me on this to solve this error?

Thank you

Class 'kato\DropZone' not found

hi,
In my application I did so in VIEW:

    <?php
    echo \kato\DropZone::widget([
       'options' => [
           'maxFilesize' => '2',
       ],
       'clientEvents' => [
           'complete' => "function(file){console.log(file)}",
           'removedfile' => "function(file){alert(file.name + ' is removed')}"
       ],
   ]);

But show

PHP Fatal Error โ€“ yii\base\ErrorException
Class 'kato\DropZone' not found
?>

Bad Request (#400)

Hi

There is a problem with the csrf token (Bad Request (#400)), so I added the csrf token :

'options' => [
    'url' => Url::to(['dropzone']),
    'headers' => [
        Yii::$app->getRequest()->csrfParam => Yii::$app->getRequest()->csrfToken
    ]
],

But it still not working. What is the solution ?
Waiting your answer I added public $enableCsrfValidation = false; in the Controller

Thank you

AutoDiscover configuration ignored

I'm using Chromium (Chrome) and I've a couple of errors in the javascript console:

Uncaught Error: No URL provided.
Uncaught Error: Dropzone already attached.

registerJs() by default bind/wrap its code to the onready event (using jQuery) and this addon use it to configure the AutoDiscover option to true or false.

asset::register() doesn't bind/wrap to anything, as it should be for any javascript library/module, it is included at the end of the body after its dependencies and executed as soon as possible.

The problem is that DropZone, at least the version used by this addon, execute as soon as possible a contentLoaded function that seems to bind to the onload event, when the content is loaded the autoDiscover start.

So what is happening (at least on the Chromium I'm using) is that the DropZone's autoDiscover function is executed before the addon javascript set the autoDiscover configuration.

Currently the only solution I've found is to add a new asset, with the js code to disable the autoDiscover, add to it DropZoneAsset as dependency, and in DropZone.php register it instead, but is far from optimal.

widget error

installed with composer

when using widget i get:

PHP Fatal Error โ€“ yii\base\ErrorException
Class 'yii\base\widget' not found

at class DropZone extends \yii\base\widget {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.