0

I have written one jquery code of upload files with Web Handler. It works fine but i want to check if file's extension is not matching with my criteria than it will not allow to upload the file..

Here is my code

$(document).ready(function () {

            var button = $('#fuAttachment'), interval;
            $.ajax_upload(button, {
                action: 'FileUploader.ashx',
                name: 'myfile',
                onSubmit: function (file, ext) {
                    if (ext == "js") {
                        alert(ext);
                    }
                    //  this.disable();
                },
                onComplete: function (file, response) {
                    window.clearInterval(interval);
                    $('<li></li>').appendTo('.files').text(file);
                }
            });
            });

I am getting the extension in ext variable. I can check it also but still if file contain that extension than want to break upload operation.
How can i do this?? please help ME if anybody knows..

2
  • What's $.ajax_upload? Where does it come from? Custom written (if so, please show the code)? Third party upload plugin (if so please post a link to the website of the plugin)? Commented Jun 29, 2012 at 7:42
  • @DarinDimitrov: It comes from jquery library jquery.ajax_upload.0.6.min.js. You can get it from this link Commented Jun 29, 2012 at 7:43

1 Answer 1

1

You could return false from the onSubmit function to prevent the file upload if some condition is not satisfied:

onSubmit: function (file, ext) {
    if (ext == "js") {
        // the extension of the selected file was .js => allow upload
        return true;
    }

    // the extension is not .js => don't do the upload
    return false;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.