In one of my form ( jquery + html + php ) I have to check the extension of file before uploading to the server. ie. User is only allowed to upload .jpg files only and within fixed dimensions for eg: 150px X 100px. For this I will have to write a client-side validation using javascript.
Add a comment
|
2 Answers
Javascript cannot check the true type of a file. This means that a user can upload a BMP file by renaming it to a jpg extension.
However a sample javascript code that can do the work is:
// Assume that filename is a variable that holds the filename
if(filename.lastIndexOf(".jpg") == -1) {
return false;
}
else {
return true;
}