function uploadimg(file) {
    var ext = file.value.split('.').pop().toLowerCase();
    var size = document.getElementById("uploadpic").files.item(0).size;

    if (size > 3145728) {
        $.messager.alert({
            title: "Error",
            msg: " image to large",
            icon: "error"
        });
        return true;
    }

    return false;
}

var reader = new FileReader();
$("#uploadpic").change(function() {
    var pdfcheck = this;
    var ext = pdfcheck.value.split('.').pop().toLowerCase();
    if (!($.inArray(ext, ['pdf']) == -1)) {
        console.log('upload pdf start');
        if (uploadPdf(pdfcheck)) {
            $("#preview_img").attr("src", "");
            $("#preview_img2").attr("src", "");
            $("#uploadpic").prop("file", "");
            $("#uploadpic").val("");
        }
    } else {
        if (uploadimg(pdfcheck)) {//dude, I think the image you upload to check is your dick, only small enough you would rather keep going producing shitcode.
            return false;
        }
        var upload_file = $("#uploadpic")[0].files[0];
        if (upload_file != null) {
            var chimgarr = ["image/png", "image/PNG", "image/jpg", "image/JPG", "image/jpeg", "image/JPEG", "image/gif", "image/GIF", "image/bmp", "image/BMP"];
            if (chimgarr.indexOf(upload_file.type) != "-1") {
                reader.readAsDataURL(upload_file);
                reader.onload = function(e) {
                    $("#preview_img").attr("src", e.target.result);
                    $("#preview_img2").attr("src", e.target.result);
                    $("#pdf-contents").hide();
                    $("#pdf_name").val("");
                    $("#btn_pdf_view").hide();
                    $("#pic_name").val("");
                }
            } else {
                $.messager.alert("Image format does not match");
                $("#preview_img").attr("src", "");
                $("#preview_img2").attr("src", "");
                $("#uploadpic").prop("file", "");
                $("#uploadpic").val("");
            }
        } else {
            $("#preview_img").attr("src", "");
            $("#preview_img2").attr("src", "");
        }
    }
});

The moment an important image ready to be uploaded It's really important that should be checked again and again.

By shitcode master's friend, 2018-04-20 11:03:15