jpajk
8/11/2017 - 9:52 AM

Pluploader

Pluploader

<?= $this->Html->script('/plugins/plupload/js/plupload.js') ?>
<?= $this->Html->script('/plugins/plupload/js/plupload.flash.js') ?>
<?= $this->Html->script('/plugins/plupload/js/plupload.html4.js') ?>
<?= $this->Html->script('/plugins/plupload/js/plupload.html5.js') ?>

<script type="application/javascript">
    var dropElement = '<?= $drop_element ?>';
    var browseButton = '<?= $browse_button ?>';
    var uploadUrl = '<?= $upload_url ?>';
</script>

<script type="text/javascript">
var uploader = new plupload.Uploader({
    drop_element: dropElement,
    runtimes: 'html5,html4,flash',
    browse_button: browseButton,
    container: dropElement,
    max_file_size: '30mb',
    chunk_size: '50kb',
    unique_names: true,
    multi_selection: true,
    multipart: true,
    url : uploadUrl,
    flash_swf_url: '/js/plugins/plupload/js/plupload.flash.swf',
    preinit: {
        UploadFile: function (up, file) {
            up.settings.multipart_params = {
                original_name: file.name
            };
        }
    },
    multipart_params: {
        "provider": 1,
    },
    Error: function(up, err) {
        $('console').innerHTML += "\nError #" + err.code + ": " + err.message;
    }
});

uploader.bind('Init', function (up, params) {
    $('#upload-unavailable1').remove();
    $('#filelist1').hide();
});

uploader.init();
uploader.bind('FilesAdded', function () {
    uploader.start();
});

uploader.bind('FileUploaded', function (up, file, info) {
    var res = JSON.parse(info.response)
    flash.parse(res);

    if (res.status === 1) {
        processFileUploaded(res);
    }
});

uploader.bind('UploadProgress', function (up, file) {
    topProgressBar.display();

    topProgressBar.go(file.percent);

    if (file.percent > 99) {
        topProgressBar.hide();
    }
});
</script>