在Wordpress上传中显示文件大小或MP3文件持续时间

时间:2019-02-08 15:14:33

标签: javascript php jquery ajax wordpress

我正在使用允许文件上传的付费插件。我想显示上传文件的大小,最好显示MP3文件的持续时间。有谁知道如何在此Javscript函数中完成此操作?

    function wcpa_upload_file(e) {
        var a = e.prop("files")[0];
        if (void 0 !== a) {
            "object" == typeof e.data("wcpa_ajx_upload") && e.data("wcpa_ajx_upload").abort();
            var t = e.val().match(/([^\/\\]+)$/)[1],
                r = e.parents(".wcpa_file_outer");
            if (r.find(".wcpa_file_name").removeClass("wcpa_file_error").html(t), e.is(".wcpa_ajax_upload")) {
                var i = new FormData,
                    n = e.data("details");
                i.append("wcpa_file", a), i.append("wcpa_file_details", JSON.stringify(n)), i.append("action", "wcpa_ajax_upload"), !0 === n.required && e.attr("required", "required");
                var c = $.ajax({
                    type: "POST",
                    url: wcpa_global_vars.ajax_url,
                    xhr: function() {
                        var e = $.ajaxSettings.xhr();
                        return e.upload && e.upload.addEventListener("progress", function(e) {
                            if (e.lengthComputable) {
                                var a = Math.round(100 * e.loaded / e.total);
                                $("~ .wcpa_progress", r).css("width", a + "%")
                            }
                        }, !1), e
                    },
                    beforeSend: function() {
                        e.parent().addClass("wcpa_uploading"), e.parent().removeClass("wcpa_uploaded"), $("~ .wcpa_progress", r).show().css("width", 0), $("~ .wcpa_file_hidden", r).val(""), e.parents("form").find(".single_add_to_cart_button").addClass("wcpa_disable_cart");
                        var a = parseInt(e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count"));
                        isNaN(a) ? a = 1 : a++, e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count", a)
                    },
                    success: function(a) {
                        $("~ .wcpa_progress", r).show().css("width", 100), e.parent().removeClass("wcpa_uploading"), $("~ .wcpa_progress", r).show(), e.val("");
                        var t = parseInt(e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count"));
                        isNaN(t) || 1 === t ? (t = 0, e.parents("form").find(".single_add_to_cart_button").removeClass("wcpa_disable_cart")) : t--, e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count", t), !0 === a.status ? (e.removeAttr("required"), $("~ .wcpa_progress", r).css("width", "100%"), $("~ .wcpa_file_hidden", r).val(a.file.file + "||" + a.file.file_name), e.parent().addClass("wcpa_uploaded")) : ($("~ .wcpa_progress", r).css("width", 0), r.find(".wcpa_file_name").addClass("wcpa_file_error").html(a.message))
                    },
                    error: function(a, t, i) {
                        $("~ .wcpa_progress", r).show().css("width", 0);
                        var n = parseInt(e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count"));
                        isNaN(n) || 1 === n ? (n = 0, e.parents("form").find(".single_add_to_cart_button").removeClass("wcpa_disable_cart")) : n--, e.parents("form").find(".single_add_to_cart_button").data("wcpa-upload-count", n), "abort" !== i && (e.val(""), r.find(".wcpa_file_name").addClass("wcpa_file_error").html(wcpa_global_vars.strings.ajax_upload_error)), e.parent().removeClass("wcpa_uploading")
                    },
                    async: !0,
                    data: i,
                    dataType: "json",
                    cache: !1,
                    contentType: !1,
                    processData: !1
                });
                e.data("wcpa_ajx_upload", c)
            }
        }
    }

目前,它仅显示上传后的文件名。

这里有一个关于访问JS中文件大小属性的参考,但是不确定如何在此处输出的文件名旁边使用它。

document.getElementById('file').files[0].size

https://www.codexworld.com/how-to/get-file-info-name-size-type-javascript/

enter image description here

0 个答案:

没有答案