An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)

Overview

Krajee Logo
yii2-widget-fileinput
Donate

Stable Version Unstable Version License Total Downloads Monthly Downloads Daily Downloads

The FileInput widget is a customized file input widget based on Krajee's Bootstrap FileInput JQuery Plugin. The widget enhances the default HTML file input with various features including the following:

  • Specially styled for Bootstrap 3.x, 4.x and 5.x with customizable buttons, caption, and preview
  • Ability to select and preview multiple files
  • Includes file browse and optional remove and upload buttons.
  • Ability to format your file picker button styles
  • Ability to preview files before upload - images and/or text (uses HTML5 FileReader API)
  • Ability to preview multiple files of different types (both images and text)
  • Set your upload action/route (defaults to form submit). Customize the Upload and Remove buttons.
  • Internationalization enabled for easy translation to various languages

NOTE: This extension is a sub repo split of yii2-widgets. The split has been done since 08-Nov-2014 to allow developers to install this specific widget in isolation if needed. One can also use the extension the previous way with the whole suite of yii2-widgets.

Installation

The preferred way to install this extension is through composer. Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

To install, either run

$ php composer.phar require kartik-v/yii2-widget-fileinput "@dev"

or add

"kartik-v/yii2-widget-fileinput": "@dev"

to the require section of your composer.json file.

Refer the CHANGE LOG for details of release wise changes.

Demo

You can refer detailed documentation and demos on usage of the extension.

Usage

use kartik\file\FileInput;

// Usage with ActiveForm and model
echo $form->field($model, 'avatar')->widget(FileInput::classname(), [
    'options' => ['accept' => 'image/*'],
]);

// With model & without ActiveForm
echo '<label class="control-label">Add Attachments</label>';
echo FileInput::widget([
    'model' => $model,
    'attribute' => 'attachment_1',
    'options' => ['multiple' => true]
]);

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

yii2-widget-fileinput is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

Comments
  • Multiple file input instances renders incorrectly.

    Multiple file input instances renders incorrectly.

    This is my view code:

    echo '<label class="control-label">One</label>';
    echo FileInput::widget([
        'model' => new UploadForm(),
        'attribute' => 'file',
    ]);
    echo '<label class="control-label">Two</label>';
    echo FileInput::widget([
        'model' => new UploadForm(),
        'attribute' => 'file',
    ]);
    

    I see this on the page. Second input is spinning infinitely. default

    As I understand problem is in same attribute for both widgets.

    opened by StalkAlex 9
  • Initial Preview remove buttons do not work

    Initial Preview remove buttons do not work

    The initial preview works perfectly, except the small red remove buttons don't do anything when you click them. In order to remove you have to remove all the files.

    Your demo suffers from this same issue.

    I did notice that after you select a new file the remove buttons on the existing files begins to work.

    opened by cornernote 8
  • issue with Yii2 CSRF cookie validation failing;

    issue with Yii2 CSRF cookie validation failing; "Unable to verify your data submission"

    I kept getting 400 "Unable to verify your data submission." errors from the controller where the upload heads. I've verified that the CSRF token is in the header as well as at the start of the form definition as a hidden input but still no luck.

    I managed to get it working again with correct CSRF token validation by adding the following option to the widget:

    'options' => [
        'uploadExtraData'=> new \yii\web\JsExpression('_csrf:yii.getCsrfToken()'),
    ],
    

    Strangely before my addition, the request did contain a CSRF cookie, but its value wasn't valid; it failed the check in \yii\base\Security validateData().

    help wanted 
    opened by ASlatius 8
  • PHP warning caused by duplicate property definition

    PHP warning caused by duplicate property definition

    Hello there!

    The latest version of yii2-krajee-base breaks the file input widget under PHP 5.6.

    Steps to reproduce the issue

    1. Update yii2-krajee-base to latest release
    2. Try to use the file input widget under PHP 5.6 with strict warnings enabled

    Expected behavior and actual behavior

    Following the steps above, this warning is thrown: file_input_warning

    This is not the case using at least PHP 7.0, or even disabling strict warnings, but there can be (and there are, in fact) hosts where we cannot turn off the warnings even if we want to, so it would still be great to fix this.

    Environment

    Libraries

    • yii2-krajee-base version: 1.9.4
    • yii2-widget-fileinput version: 1.0.6

    It seems to me that this needs to be fixed in this extension, and not in yii2-krajee-base, I hope I am correct in opening the issue here.

    opened by gyula-szabo 7
  • The message file for category 'fileinput' does not exist

    The message file for category 'fileinput' does not exist

    I get an error message: "The message file for category 'fileinput' does not exist: ..\site\vendor\kartik-v\yii2-krajee-base/messages/ru-RU/fileinput.php Fallback file does not exist as well: ..\site\vendor\kartik-v\yii2-krajee-base/messages/ru/fileinput.php"

    duplicate 
    opened by uagrace 6
  • Custom internationalization

    Custom internationalization

    I have to customize the internationalization and noticed that this is not possible right now, because of one * char.

    // This
    // Yii::$app->i18n->translations['fileinput'] = $this->i18n;
    // Should be
    Yii::$app->i18n->translations['fileinput*'] = $this->i18n;
    
    question 
    opened by aliechti 6
  • Are themes also available in yii2-widget-fileinput

    Are themes also available in yii2-widget-fileinput

    Hi,

    Are themes also available in yii2 file input?

    I've tried with

     'pluginOptions' => [
                        'theme' => 'explorer',
    

    without success and couldn't find something in the docu or web.

    Thanks a lot!

    Toby

    opened by strtob 5
  • File Input rendering hidden input field

    File Input rendering hidden input field

    I added the FileInput widget in a form like below.

    <?php echo '<label class="control-label">Add Attachments</label>';
        echo FileInput::widget([
            'model' => $model,
            'attribute' => 'image',
            'options' => [
                'multiple' => false,
                'accept'=>'image/*'
            ],
            'pluginOptions'=>['allowedFileExtensions'=>['jpg','gif','png']]
        ]);
        ?>
    

    and I added encryption type to formdata to the form like below.

    <?php $form = ActiveForm::begin([
            'options'=>['enctype'=>'multipart/form-data'] // important
        ]); ?>
    

    The above widget rendering the code like below.

    <label class="control-label">Add Attachments</label>
    <input type="hidden" name="Notification[image]" value="">
    <input type="file" id="notification-image" class="file-loading" name="Notification[image]" accept="image/*" data-krajee-fileinput="fileinput_fd8fa034">
    <!--[if lt IE 10]><br><div class="alert alert-warning"><strong>Note:</strong> Your browser does not support file preview and multiple file upload. Try an alternative or more recent browser to access these features.</div><script>document.getElementById("notification-image").className.replace(/\bfile-loading\b/,"");;</script><![endif]-->
    

    In the output there is two input tag(hidden and a file) with same name is added. So when i submit the form the controller accepting the first hidden tag value only which is empty always. But the actual value is storing in the second tag only which is not accept as a request.

    opened by mahendran-sakkarai 5
  • How to display a confirm box upon file delete icon click?

    How to display a confirm box upon file delete icon click?

    Dear Kartik,

    How to program a confirmation dialog for the user when they click on the delete icon on the preview of an existing image / file? This is my current code in controller -

    echo $form->field($model, 'images[]')->widget(FileInput::classname(), [ 'options' => ['accept' => 'image/*', 'multiple' => true], 'pluginOptions' => [ 'allowedFileExtensions' => ['jpg', 'gif', 'png'], 'initialPreview' => [ Html::img("/images/moon.jpg", ['class' => 'file-preview-image', 'alt' => 'The Moon', 'title' => 'The Moon']), Html::img(Yii::$app->params['imagesUrl'] . "default.png", ['class' => 'file-preview-image', 'alt' => 'The Earth', 'title' => 'The Earth']), ], 'initialPreviewConfig' => [ [ 'caption' => 'The Moon', 'url' => Url::toRoute(['page/removefile', 'file' => 'moon.png']), ], [ 'caption' => 'Default', 'url' => Url::toRoute(['page/removefile', 'file' => 'default.png']), ], ], ] ]);

    question 
    opened by vkmel 5
  • Why initial preview images removed after click upload new button

    Why initial preview images removed after click upload new button

    1

    This is the markup:

    <?= $form->field($model, 'upload_file')->widget(FileInput::class, [
        'options' => [
            'multiple' => true,
        ],
        'pluginOptions' => [
            'showCaption' => false,
            'initialPreview' => $model->getPreviewThumbs(),
            'initialPreviewConfig' => $model->previewConfig,
            'uploadUrl' => Url::to(['/upload/single']),
        ],
        'pluginEvents' => [
            'filedeleted' => 'function() {console.log(arguments)}',
            'fileuploaded' => $fileUploadEvent,
        ]
    ]) ?>
    
    opened by lichunqiang 4
  • Not able to change plugin language

    Not able to change plugin language

    Hi @kartik-v !

    I'm not able to change language to russian.

    Here is my code:

    <?= $form->field($model, 'image')->widget(FileInput::classname(), [
            'options' => ['accept' => 'image/*'],
            'language' => 'ru',
            'pluginOptions' => [
                'initialPreview' => $preview_images,
                'overwriteInitial'=>false,
                'showRemove' => false,
            ],
        ]); ?>
    

    Is it possible to change language if I'm not using Ajax? Because as per docs Ajax and custom language come together.

    opened by DenisAlliswell 4
Releases(v1.1.1)
  • v1.1.1(Jun 28, 2022)

    Date: 28-Jun-2022

    • (enh #186): New property autoFileTypeParsing for parsing file types.
    • (enh #185): Add Uzbek (Cyrillic) language translations.
    • (enh #184): Add Uzbek (Cyrillic) language in messages config.
    • (enh #180): Enhancements to support Bootstrap v5.x.
    • (bug #179): Support translations for language codes with hyphen.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Oct 23, 2020)

    Date: 24-Oct-2020

    • (enh #171): Eliminate DOM Purify plugin and assets dependencies.
    • (enh #169): Add German Translations.
    • (enh #165): Add Latvian Translations.
    • (enh #162): Add Uzbek Translations.
    • (enh #159): Add Romanian Translations.
    • (enh #157): Add Armenian Translations.
    • Bump composer dependencies.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.9(Apr 19, 2019)

  • v1.0.8(Sep 19, 2018)

  • v1.0.7(Sep 7, 2018)

    Date: 07-Sep-2018

    • Updates to support Bootstrap 4.x.
    • (kartik-v/yii2-krajee-base#94): Refactor code and consolidate / optimize properties within traits.
    • Reorganize relevant code in "src" directory.
    • Optimize asset bundles.
    • (enh #134): Add Slovak Translations.
    • (enh #126): Add Finnish Translations.
    • (enh #120): Add Explorer FA Theme support.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.6(May 25, 2017)

    Date: 26-May-2017

    • Enhancements for plugin v4.4.1 (inclusion of PiExifAsset and removal of CanvasBlobAsset).
    • Add github contribution and issue/PR log templates.
    • Update copyright year to current.
    • (enh #117): Add Bulgarian Translations.
    • (enh #114): Automatically add enctype to form options when using with Yii Active Field and Active Form.
    • (enh #112): Add Explorer Theme support.
    • (enh #90): Fixed namespace fatal error.
    • (enh #88): Add Vietnamese Translations.
    • (enh #79): Add Lithuanian Translations.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.5(Jun 16, 2016)

    Date: 16-Jun-2016

    • (enh #70): Add Estonian Translations.
    • (enh #71): Enhancements for plugin v4.3.2.
    • Add branch alias for dev-master latest release.
    • (enh #74): Add Ukranian Translations.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.4(Jan 10, 2016)

    Date: 10-Jan-2016

    • (enh #36): Add Indonesian Translations
    • (enh #37): Add Greek Translations
    • (enh #40): Add Persian Translations
    • (enh #57): Enhance localizations and allow yii to generate message files via config.
    • (enh #58): Enhancements for PJAX based reinitialization. Complements enhancements in kartik-v/yii2-krajee-base#52 and kartik-v/yii2-krajee-base#53.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Jun 26, 2015)

  • v1.0.2(May 4, 2015)

    Date: 03-May-2015

    • (enh #23): Add Chinese translations.
    • (enh kartik-v/yii2-krajee-base#34, kartik-v/yii2-krajee-base#35): Enhance i18n translation locales.
    • (enh #29): Better validation for graceful downgrade for older browsers.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Mar 31, 2015)

    Date: 30-Mar-2015

    • (enh #4): Hungarian translations
    • (enh #20): Croatian translations
    • (enh #21): Updates to widget for v4.1.8 bootstrap-fileinput plugin
      • All plugin related translations now reside in the locales files in the plugin folder. Pull requests for new translations or editing translations needs to be done in the plugin folder.
      • The language property can be set at the widget level to set the language (this will default to Yii::$app->language).
    • (enh #22): Added Thai language translations.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Nov 9, 2014)

Owner
Kartik Visweswaran
Kartik Visweswaran
An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)

yii2-widget-rangeinput The RangeInput widget is a customized range slider control widget based on HTML5 range input. The widget enhances the default H

Kartik Visweswaran 19 Mar 12, 2022
Tarantool connector for yii2 framework. Allow to use activerecord, schemas, widgets and more.

Tarantool connector for yii2 framework Tarantool connector for yii2 framework. Allow to use framework abstractions such as ActiveRecord, Schema, Table

Andrey 11 Nov 21, 2021
Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker

Yii2 Date/Time Picker Widget Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker Demo Since this is a part of

Yevhen Terentiev 8 Mar 14, 2022
A Yii2 module for embedding social plugins and widgets.

yii2-social Module that enables access to social plugins for Yii Framework 2.0. It includes support for embedding plugins from the following networks

Kartik Visweswaran 92 May 29, 2022
Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

Kartik Visweswaran 38 Sep 21, 2022
Simple RBAC Manager for Yii2 (minify of yii2-admin)

Yii2 Mimin Simple RBAC Manager fo Yii 2.0. Minify of yii2-admin extension with awesome features Attention Before you install and use this extension, t

Hafid Mukhlasin 52 Sep 22, 2022
yii2-app-advanced with Twitter Bootstrap 5

Yii 2 Advanced Project Template is a skeleton Yii 2 application best for developing complex Web applications with multiple tiers.

Nedarta 1 Nov 5, 2021
Yii 2 widget for the Froala WYSIWYG HTML Editor.

Yii Framework Froala WYSIWYG HTML Editor Yii 2 widget for Froala Wysiwyg editor. Installation The preferred way to install this extension is through c

Froala 99 Sep 21, 2022
Extends Yii Menu widget

Extends Yii Menu widget. This widget offers a scrollspy and affixed enhanced navigation (upto 2-levels) to highlight sections and secondary sections in each page.

Kartik Visweswaran 15 Mar 12, 2022
DepDrop widget is a Yii 2 wrapper for the dependent-dropdown jQuery plugin by Krajee.

yii2-widget-depdrop The DepDrop widget is a Yii 2 wrapper for the dependent-dropdown jQuery plugin by Krajee. This plugin allows multi level dependent

Kartik Visweswaran 82 Nov 27, 2022
Web Push Notifications brought to Yii2

Web Push Notifications for Yii 2 An extension for implementing Web Push Notifications on your website in a breeze. Documentation is at docs/README.md

Mehdi Achour 12 May 19, 2022
Prometheus exporter for Yii2

yii2-prometheus Prometheus Extension for Yii 2 This extension provides a Prometheus exporter component for Yii framework 2.0 applications. This extens

Mehdi Achour 3 Oct 27, 2021
Yii2-symfonymailer - Yii 2 Symfony mailer extension.

Yii Mailer Library - Symfony Mailer Extension This extension provides a Symfony Mailer mail solution for Yii framework 2.0. For license information ch

Yii Software 28 Dec 22, 2022
Yii2 console application used to write our processors of methods to responsible to client calling.

Microservice Application Skeleton Yii2 console application used to write our processors of methods to responsible to client calling. This application

Jafaripur 0 Mar 10, 2022
Yii2 extension for format inputs based on AutoNumeric.js

Yii2 extension for format inputs based on AutoNumeric.js

extead 2 Oct 7, 2019
Pug Yii2 adapter

Yii 2 Pug (ex Jade) extension This extension provides a view renderer for Pug templates for Yii framework 2.0 applications. Support GutHub issues Inst

Pug PHP 8 Jun 17, 2022
This is Yii2 utilities

YII2-UTILITY This is Yii2 utilities. Requirements PHP >= 7.4 Curl extension for PHP7 must be enabled. Download Using Composer From your project direct

null 0 Jun 30, 2022
Alejandro Flores, Php Yii2 Emoac

Prueba Tecnica Emoac Proyecto basado en PHP con Yii2. Hecho por Alejandro Flores, Ingeniero en informática. Este proyecto consta de un CRUD de product

FlamesAlejandro 2 Sep 13, 2022
🔭 Proof of concept on adding observability features (tracing and metrics) to a Nano microservice (using existing Hyperf components).

?? Tracing Nano Proof of concept on adding observability features (tracing and metrics) to a Nano microservice (using existing Hyperf components ?? ).

Leo Cavalcante 4 Oct 24, 2022