简体   繁体   中英

fileupload control for multiple files, extension check

I have file upload control for uploading multiple files. Like this

 <ajaxToolkit:AsyncFileUpload ClientIDMode="Static" name="aa[]" BackColor="Azure"
         ForeColor="Black" OnClientUploadError="uploadError" OnClientUploadStarted="abc"
         multiple="multiple" OnClientUploadComplete="uploadComplete" runat="server" 
         ID="AsyncFileUpload1" Width="400px" CompleteBackColor="White" 
         UploadingBackColor="#CCFFFF" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />

I want to allow only jpg png and gif file types to get uploaded.

How can I achieve this in javascript and jquery?

So the real thing is how can I access file names from fileupload control and checking extension?

You can use function OnClientUploadStarted as follows use a function name in this event as follows

OnClientUploadStarted="AssemblyFileUpload_Started"

and write a function as below

function AssemblyFileUpload_Started(sender, args) {
    var filename = args.get_fileName();
    var ext = filename.substring(filename.lastIndexOf(".") + 1);
    if (ext != 'png') {
        throw { 
            name:        "Invalid File Type", 
            level:       "Error", 
            message:     "Invalid File Type (Only .png)",
            htmlMessage: "Invalid File Type (Only .png)" 
        }
        return false;
    }
    return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM