PoliDev
PoliDev

Reputation: 1458

how to restrict the files uploading using jquery

I am doing the following steps to upload the file. But it is accepting all types of files.I want to restrict to do .pdf and .doc alone. How to do ?

My code

<input type="file" id="Resume"/>

Jquery

Candidate.AddUploadResumeBehavior = function () {
$('#Resume').uploadify({ 
    'swf': root + '/Content/Flash/uploadify.swf',
    'uploader': root + '/Candidates/UploadResume',
    'cancelImg': root + '/Content/Images/uploadify-cancel.png',
    'auto': true,
    'multi': true,
    'fileDesc': 'Image Files',
    'fileExt': '*.jpg;*.png;*.gif;*.pdf;*.bmp;*.jpeg;*.doc',
    'queueSizeLimit': 90,
    'sizeLimit': 4000000,
    'buttonText': 'Upload Resume',
    'width': 200,
    'folder': root + '/uploads',
    'onComplete': function (event, queueID, fileObj, response, data) {
        Dial4Jobz.Common.ShowMessageBar("Resume has been uploaded.");
    },
    'onError': function (event, ID, fileObj, errorObj) {
        var msg;
        if (errorObj.type === "File Size")
            msg = 'File size cannot exceed 4MB';
        else
            msg = "An error occured while attempting to uploading resume."

        Common.ShowMessageBar(msg);
        this.hide();
    }
});

};

Here i have tried to change the extensions files '*.jpg;*.png;*.gif;*.pdf;*.bmp;*.jpeg;*.doc' into '*.doc; *.pdf'. But it is not changed. how to do this?

Upvotes: 0

Views: 145

Answers (2)

Zane6888
Zane6888

Reputation: 36

Implement the onSelect callback function and check every file for its type. Remove files with invalid types by calling

$jQuery('#uploadify').uploadifyCancel(queueID)

Upvotes: 0

Yunus Aslam
Yunus Aslam

Reputation: 2466

I think this should fix your issue :

'fileTypeExts' : '*.gif; *.jpg; *.png'.....

Instead of "fileExt" use "fileTypeExts" and your issue shall be fixed..

Upvotes: 1

Related Questions