更改REGEX javascript代码以接受pdf文件[关闭]

I used pure php upload to create an upload page. It can however only upload the following image extensions. gif|jpg|png|bmp|jpeg

I looked in the Script library and found this code in the javascript file

re=new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");

I am sure this is the code I need to modify to allow pdf files to be uploaded. For Javascript experts, the entire code is as follows. Please help will be appreciated

 /* 
    Pure PHP Upload
    Copyright 2001-2010 (c) George Petrov, www.DMXzone.com
    Version: 2.1.12
*/

function checkFileUpload(c, h, f, d, a, m, j, k, e, l) {
    if (document.MM_returnValue === false) {
        return
    }
    var b = true;
    document.MM_returnValue = false;
    for (var g = 0; g < c.elements.length; g++) {
        field = c.elements[g];
        if (!field.type || field.type.toUpperCase() != "FILE") {
            continue
        }
        checkOneFileUpload(field, h, f, d, a, m, j, k, e, l);
        if (!field.uploadOK) {
            b = false;
            break
        }
    }
    if (b) {
        document.MM_returnValue = true
    }
}

function checkOneFileUpload(g, f, d, b, a, k, h, i, c, j) {
    var e = g.value.replace(/"/gi, "");
    g.uploadOK = false;
    if (e == "") {
        if (d) {
            alert("File is required!");
            g.focus();
            return
        } else {
            g.uploadOK = true
        }
    } else {
        if (f != "") {
            checkFileExtension(g, e, f)
        } else {
            g.uploadOK = true
        }
        if (!document.layers && g.uploadOK) {
            document.PU_uploadForm = g.form;
            re = new RegExp(".(gif|jpg|png|bmp|jpeg)$", "i");
            if (re.test(e) && (b != "" || a != "" || k != "" || h != "" || i != "" || c != "" || j != "")) {
                checkImageDimensions(g, b, a, k, h, i, c, j)
            }
        }
    }
    return
}

function checkFileExtension(j, e, h) {
    var l = new RegExp("\\.(" + h.replace(/,/gi, "|").replace(/\s/gi, "") + ")$", "i");
    var d = navigator.userAgent.toLowerCase();
    var b = (d.indexOf("mac") != -1);
    var a = (d.indexOf("opera") != -1);
    if (a) {
        var c = e.substring(e.lastIndexOf(".") + 1, e.length);
        var k = h.split(",");
        var g = false;
        for (var f = 0; f < k.length; f++) {
            if (k[f].toLowerCase() == c.toLowerCase()) {
                g = true;
                break
            }
        }
        if (g == false) {
            alert("This file type is not allowed for uploading.
Only the following file extensions are allowed: " + h + ".
Please select another file and try again.");
            j.focus();
            j.uploadOK = false;
            return
        }
    } else {
        if (!l.test(e)) {
            alert("This file type is not allowed for uploading.
Only the following file extensions are allowed: " + h + ".
Please select another file and try again.");
            j.focus();
            j.uploadOK = false;
            return
        }
    }
    j.uploadOK = true
}

function checkImageDimensions(field, sizeL, minW, minH, maxW, maxH, saveW, saveH) {
    var agt = navigator.userAgent.toLowerCase();
    var is_mac = (agt.indexOf("mac") != -1);
    var is_ie = document.all;
    var is_ns6 = (!document.all && document.getElementById ? true : false);
    var fileURL = field.value;
    if (is_ie && is_mac) {
        begPos = fileURL.indexOf("/", 1);
        if (begPos != -1) {
            fileURL = fileURL.substring(begPos + 1, fileURL.length)
        }
    }
    fileURL = "file:///" + fileURL.replace(/:\\/gi, "|/").replace(/\\/gi, "/").replace(/:([^|])/gi, "/$1").replace(/"/gi, "").replace(/^\//, "");
    if (!field.gp_img || (field.gp_img && field.gp_img.src != fileURL) || is_ns6) {
        if (is_ie && is_mac) {
            var dummyImage;
            dummyImage = document.createElement("IMG");
            dummyImage.src = "dummy.gif";
            dummyImage.name = "PPP";
            field.gp_img = dummyImage
        } else {
            field.gp_img = new Image()
        }
        with(field) {
            gp_img.field = field;
            gp_img.sizeLimit = sizeL * 1024;
            gp_img.minWidth = minW;
            gp_img.minHeight = minH;
            gp_img.maxWidth = maxW;
            gp_img.maxHeight = maxH;
            gp_img.saveWidth = saveW;
            gp_img.saveHeight = saveH;
            gp_img.onload = showImageDimensions;
            gp_img.src = fileURL + "?a=123"
        }
    }
}

function showImageDimensions(c) {
    var b = (!document.all && document.getElementById ? true : false);
    var a = (c && !b ? c : this);
    if (a.width > 0 && a.height > 0) {
        if ((a.minWidth != "" && a.minWidth > a.width) || (a.minHeight != "" && a.minHeight > a.height)) {
            alert("Uploaded Image is too small!
Should be at least " + a.minWidth + " x " + a.minHeight);
            a.field.uploadOK = false;
            return
        }
        if ((a.maxWidth != "" && a.width > a.maxWidth) || (a.maxHeight != "" && a.height > a.maxHeight)) {
            alert("Uploaded Image is too big!
Should be max " + a.maxWidth + " x " + a.maxHeight);
            a.field.uploadOK = false;
            return
        }
        if (a.sizeLimit != "" && a.fileSize > a.sizeLimit) {
            alert("Uploaded Image File Size is too big!
Should be max " + (a.sizeLimit / 1024) + " KBytes");
            a.field.uploadOK = false;
            return
        }
        if (a.saveWidth != "") {
            document.PU_uploadForm[a.saveWidth].value = a.width
        }
        if (a.saveHeight != "") {
            document.PU_uploadForm[a.saveHeight].value = a.height
        }
        if (document.PU_uploadForm[a.field.name + "_width"]) {
            document.PU_uploadForm[a.field.name + "_width"].value = a.width
        }
        if (document.PU_uploadForm[a.field.name + "_height"]) {
            document.PU_uploadForm[a.field.name + "_height"].value = a.height
        }
        a.field.uploadOK = true
    }
}

function showProgressWindow(m, d, c) {
    var k = false,
        a, n;
    for (var l = 0; l < document.forms.length; l++) {
        a = document.forms[l];
        for (var e = 0; e < a.elements.length; e++) {
            n = a.elements[e];
            if (!n.type || n.type.toUpperCase() != "FILE") {
                continue
            }
            if (n.value != "") {
                k = true;
                break
            }
        }
    }
    if (k && document.MM_returnValue) {
        var o = 480,
            j = 340;
        if (document.all || document.layers || document.getElementById) {
            o = screen.availWidth;
            j = screen.availHeight
        }
        var b = (o - d) / 2,
            g = (j - c) / 2;
        document.progressWindow = window.open(m, "ProgressWindow", "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + d + ",height=" + c);
        document.progressWindow.moveTo(b, g);
        document.progressWindow.focus();
        window.onunload = function() {
            document.progressWindow.close()
        }
    }
};

To allow pdf files you will only have to add pdf in regex using alteration.

Regex: re=new RegExp("\.(gif|jpg|png|bmp|jpeg|pdf)$","i");