I would like to have jQuery limit a file upload feild to only jpg/jpeg, png, and gif. I am doing backend checking with php already. I am running my submit button through a javascript function already so I really just need to know how to check for the filetypes before submit or alert.

Thanks!

You can get the value of a file field just the same as any other field. You can't alter it, however.

So to superficially check if a file has the right extension, you could do something like this:

var ext = $('#my_file_field').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
    alert
('invalid extension!');
}
原文出處:http://stackoverflow.com/questions/651700/how-to-have-jquery-restrict-file-types-on-upload

創作者介紹

經驗交流分享與備忘

Frank 發表在 痞客邦 PIXNET 留言(0) 人氣()