jQuery-上传前检查文件扩展名 [英] jquery - Check for file extension before uploading

查看:259
本文介绍了jQuery-上传前检查文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 uploadify 通过Codeigniter上传文件.在上传文件之前,我只需要检查文件扩展名是否正确即可.我尝试使用 http://jquery.bassistance.de/以及

I am using uploadify for uploading files with Codeigniter. And before uploading the file I just have to check whether the file extension is correct is correct or not. I have tried with http://jquery.bassistance.de/ and also http://forum.jquery.com/

Bur没有得到适当的结果.谁能告诉我该怎么做?

Bur didn't got proper result. Can anyone please tell me how can I do the same?

预先感谢...

推荐答案

我要感谢发布答案的人,但是他删除了该帖子.我们可以这样做.

I would like to thank the person who posted the answer, but he has deleted the post. We can do it like this.

$("#yourElem").uploadify({
   'uploader': ...,
   'script': ...
    'fileExt' : '*.jpg;*.gif;', //add allowed extensions
    .....,
    'onSelect': function(e, q, f) {
        var validExtensions = ['jpg','gif']; //array of valid extensions
        var fileName = f.name;
        var fileNameExt = fileName.substr(fileName.lastIndexOf('.') + 1);
        if ($.inArray(fileNameExt, validExtensions) == -1){
           alert("Invalid file type");
           $("#yourElem").uploadifyCancel(q);
           return false;
        }
    }
});

感谢您的回答,它确实有效...

Thanks for the answer, it really worked...

这篇关于jQuery-上传前检查文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆