Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery - Check for file extension before uploading

Tags:

jquery

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 didn't got proper result. Can anyone please tell me how can I do the same?

Thanks in advance...

like image 604
V15HM4Y Avatar asked Feb 13 '13 11:02

V15HM4Y


People also ask

How can I tell what file type before uploading?

Using JavaScript, you can easily check the selected file extension with allowed file extensions and can restrict the user to upload only the allowed file types. For this we will use fileValidation() function. We will create fileValidation() function that contains the complete file type validation code.

Should you just check to file extension to ensure correct file type upload?

There's no error checking on these to keep them short, presumably if you use them you'll make sure the input exists first and the extensions array is valid!

What is the extension of jQuery file?

Re: jQuery Library File Name Extensionjs.


1 Answers

You can achieve this using JQuery

HTML

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

JQuery

    $("#FilUploader").change(function () {         var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];         if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {             alert("Only formats are allowed : "+fileExtension.join(', '));         }     }); 

For more info Click Here

like image 167
Golda Avatar answered Sep 20 '22 22:09

Golda