jQuery.filer上传文件名onComplete函数

时间:2017-02-09 21:24:48

标签: javascript php jquery

我使用jQuery.filer(https://github.com/CreativeDream/jQuery.filer)将图片上传到特定文件夹。我需要使用onComplete函数在javascript中检索上传文件的名称。

我已经用这种方式修改了 ajax_upload_file.php

$data = $uploader->upload($_FILES['files'], array(

'uploadDir' => '../../src/watermark/temporary/', //Upload directory {String}

'title' => "selfie_" . $_SESSION["randomcode"], //New file name {null, String, Array} *please read documentation in README.md

文件名为" social_c1d9fe747a81e7ef1df4.jpg"或" .png"或" .gif"等等。

这是js部分:

$("#filer_input").filer({
        limit: 1,
        maxSize: 5,
        extensions: ["jpg", "png", "gif"],
        changeInput: '<div class="jFiler-input-dragDrop"></div>',
        showThumbs: true,
        theme: "dragdropbox",
        uploadFile: {
            url: "src/jquery.filer/ajax_upload_file.php",
            data: null,
            type: 'POST',
            enctype: 'multipart/form-data',
            synchron: true,
            beforeSend: function(){},
            success: function(data, itemEl, listEl, boxEl, newInputEl, inputEl, id){
                var parent = itemEl.find(".jFiler-jProgressBar").parent(),
                    new_file_name = JSON.parse(data),
                    filerKit = inputEl.prop("jFiler");

                filerKit.files_list[id].name = new_file_name;

                itemEl.find(".jFiler-jProgressBar").fadeOut("slow", function(){
                    $("<div class=\"jFiler-item-others text-success\"><i class=\"icon-jfi-check-circle\"></i> Success</div>").hide().appendTo(parent).fadeIn("slow");
                });

            },
            error: function(el){
                var parent = el.find(".jFiler-jProgressBar").parent();
                el.find(".jFiler-jProgressBar").fadeOut("slow", function(){
                    $("<div class=\"jFiler-item-others text-error\"><i class=\"icon-jfi-minus-circle\"></i> Error</div>").hide().appendTo(parent).fadeIn("slow");
                });
            },
            statusCode: null,
            onProgress: null,
            onComplete: function(){

                // ...
                // Here i need to retrieve the file name e do other stuffs
                // ...

            }
        },
        files: null,
        addMore: false,
        allowDuplicates: true,
        clipBoardPaste: true,
        excludeName: null,
        beforeRender: null,
        afterRender: null,
        beforeShow: null,
        beforeSelect: null,
        onSelect: null,
        afterShow: null,
        onRemove: function(itemEl, file, id, listEl, boxEl, newInputEl, inputEl){
            var filerKit = inputEl.prop("jFiler"),
                file_name = filerKit.files_list[id].name;

            $.post('src/jquery.filer/ajax_remove_file.php', {file: file_name});
        },
        onEmpty: null,
        options: null,
        dialogs: {
            alert: function(text) {
                return alert(text);
            },
            confirm: function (text, callback) {
                confirm(text) ? callback() : null;
            }
        },
        captions: {
            button: jquery_filer_button,
            feedback: jquery_filer_feedback,
            feedback2: jquery_filer_feedback2,
            drop: jquery_filer_drop,
            removeConfirmation: jquery_filer_removeconfirmation,
            errors: {
                filesLimit: jquery_filer_fileslimit,
                filesType: jquery_filer_filestype,
                filesSize: jquery_filer_filessize,
                filesSizeAll: jquery_filer_filessizeall
            }
        }
});

由于

0 个答案:

没有答案