1. Go to this page and download the library: Download bilginnet/yii2-plupload library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bilginnet / yii2-plupload example snippets
public function actions() {
return [
'plupload' => [
'class' => \bilginnet\plupload\PluploadAction::className(),
// upload path from alias - default is '@webroot/uploads' or set your alias path sample: '@yourpath'
// set your alias into config in your main-local config file before return[]
// Yii::setAlias('@yourpath', '@webroot/uploads/');
'targetDir' => '@webroot/uploads',
'uploadComplete' => function ($filePath, $params) {
// Do something with file
}
],
];
}
<?= \bilginnet\plupload\Plupload::widget([
'url' => ['plupload'], // sync url name to action name in controller actions
// optional unique name of uploader
// will set automatically if not set
'uploader' => $uploaderName = uniqid('uploader_'),
// auto start when files selected default true
// you can set false this if you want to start uploader when form submitting
/*
sample:
$('button[type="submit"]').click(function(event) {
var _form = $('form');
// ajax form validate
$.ajax({
type: 'post',
url: 'ajaxValidateActionUrl', // set your url
data: _form.serializeArray()
}).done(function(data) {
if (data === 'true') {
// ajax validate is true
var myUploader = <?= $uploaderName