├── .gitignore ├── LICENSE ├── README.md ├── composer.json └── src ├── Canvas2BlobAsset.php ├── GalleryAsset.php ├── JQueryFileUpload.php ├── JQueryFileUploadAsset.php ├── JQueryFileUploadPlusAsset.php ├── JQueryFileUploadPlusUIAsset.php ├── JavascriptTemplatesAsset.php ├── LoadImageAsset.php ├── messages ├── en │ └── jqueryfileupload.php ├── pl │ └── jqueryfileupload.php ├── ru │ └── jqueryfileupload.php └── ua │ └── jqueryfileupload.php └── views ├── download.php ├── gallery.php ├── main.php ├── mainPlusUI.php └── upload.php /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject 2 | /vendor 3 | /composer.lock -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, limion 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of yii2-jquery-fileupload-widget nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Blueimp file upload widget for Yii2 2 | 3 | Yii2 port of [BlueImp jQuery File Upload plugin](http://blueimp.github.io/jQuery-File-Upload/). File Upload widget with multiple file selection, drag&drop support, progress bars, validation and preview images, audio and video for jQuery. 4 | Supports cross-domain, chunked and resumable file uploads and client-side image resizing. 5 | 6 | One widget, simple configuration, everything works out of the box. 7 | 8 | Inspired by https://github.com/2amigos/yii2-file-upload-widget 9 | 10 | ### Installation 11 | 12 | From command line 13 | 14 | ```bash 15 | $ composer require limion/yii2-jquery-fileupload-widget:~1.0 16 | ``` 17 | 18 | or add to your composer.json 19 | 20 | ``` 21 | "require": { 22 | "limion/yii2-jquery-fileupload-widget": "~1.0" 23 | } 24 | ``` 25 | 26 | ### Usage 27 | 28 | #### UI version 29 | See: https://blueimp.github.io/jQuery-File-Upload/index.html 30 | Please note, in case of using a "UI" version you need to embed the widget to an existing form. 31 | ```PHP 32 | 36 | = JQueryFileUpload::widget([ 37 | 'model' => $model, 38 | 'attribute' => 'img', 39 | 'url' => ['upload', 'someparam' => 'somevalue'], // your route for saving images, 40 | 'appearance'=>'ui', // available values: 'ui','plus' or 'basic' 41 | 'gallery'=>true, // whether to use the Bluimp Gallery on the images or not 42 | 'formId'=>$form->id, 43 | 'options' => [ 44 | 'accept' => 'image/*' 45 | ], 46 | 'clientOptions' => [ 47 | 'maxFileSize' => 2000000, 48 | 'dataType' => 'json', 49 | 'acceptFileTypes'=>new yii\web\JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'), 50 | 'autoUpload'=>false 51 | ] 52 | ]);?> 53 | 54 | ``` 55 | ##### Customizing the UI 56 | You can use your own templates to customize the look and feel of upload,download and main views 57 | 58 | ```PHP 59 | 63 | = JQueryFileUpload::widget([ 64 | 'model' => $model, 65 | 'attribute' => 'img', 66 | 'url' => ['upload', 'someparam' => 'somevalue'], // your route for saving images, 67 | 'appearance'=>'ui', // available values: 'ui','plus' or 'basic' 68 | 'uploadTemplateView'=>'@app/views/jqueryfileupload/upload', // upload template 69 | 'downloadTemplateView'=>'@app/views/jqueryfileupload/download', // download template 70 | 'mainView'=>'@app/views/jqueryfileupload/main', // main view with buttonbar 71 | 'formId'=>$form->id, 72 | 'clientOptions' => [ 73 | 'maxFileSize' => 2000000, 74 | 'autoUpload'=>false 75 | ] 76 | ]);?> 77 | 78 | ``` 79 | 80 | #### Plus version 81 | See: https://blueimp.github.io/jQuery-File-Upload/basic-plus.html 82 | 83 | ```PHP 84 | ') 89 | .addClass('btn btn-primary') 90 | .prop('disabled', true) 91 | .text('Processing...') 92 | .on('click', function (e) { 93 | e.preventDefault(); 94 | var $this = $(this), 95 | data = $this.data(); 96 | $this 97 | .off('click') 98 | .text('Abort') 99 | .on('click', function () { 100 | $this.remove(); 101 | data.abort(); 102 | }); 103 | data.submit().always(function () { 104 | $this.remove(); 105 | }); 106 | }); 107 | JS; 108 | 109 | $this->registerJs($js); 110 | 111 | ?> 112 | 113 | = JQueryFileUpload::widget([ 114 | 'name' => 'files[]', 115 | 'url' => ['upload', 'someparam' => 'somevalue'], // your route for saving images, 116 | 'appearance'=>'plus', // available values: 'ui','plus' or 'basic' 117 | 'options' => ['accept' => 'image/*'], 118 | 'clientOptions' => [ 119 | 'maxFileSize' => 2000000, 120 | 'acceptFileTypes'=>new yii\web\JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'), 121 | 'autoUpload'=>false 122 | ], 123 | 'clientEvents' => [ 124 | 'add' => "function (e, data) { 125 | data.context = $('
').appendTo('#files'); 126 | $.each(data.files, function (index, file) { 127 | var node = $('') 128 | .append($('').text(file.name)); 129 | if (!index) { 130 | node 131 | .append('