0

I have a scenario wherein user is trying to view an invalid image file (for example an .dll file renamed to JPG extenstion). How do I alert the user using JavaScript that this is an invalid file?

2
  • alert("invalid file type"); ? Commented Nov 19, 2009 at 10:42
  • but the file extension .JPG is valid only but the actual content is of type .dll Commented Nov 19, 2009 at 10:46

3 Answers 3

3

JavaScript, running in the browser in a standard security context, has no way to determine this.

You have to handle this check server side.

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

Comments

1

There is no way doing it using JavaScript.

Comments

0

There is a way of doing it with javascript.

If the browser supports window.FileReader and window.Blob, which most do, then yes, you can.

if ( window.FileReader && window.Blob ) { // get your file from wherever... // tacky check jpg in the mime type if ( yourFile.type.indexOf("jpeg") ) { .... } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.