0

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.

2 Answers 2

2

You can't do that in Javascript. you have to use flash based uploader like SWFUpload or Uploadify to do this.

Update:

There is one jquery upload project that I really like,

http://blueimp.github.com/jQuery-File-Upload/

Sign up to request clarification or add additional context in comments.

1 Comment

any alternate way for this with html5 ?
1

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;
}

2 Comments

thanks for the reply and actually I want to get the dimensions of the uploaded file at the time of form submit
As previsously stated, this cannot be done with pure javascript. You have to check a JavaScript library for this.

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.