Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wants check Header of upload file.For example abc.png is correct format but extension change to abc.doc this file restrict to upload.

What I have tried:

var validExtensions = ['doc','pdf','docx','odt','txt','rtf']; //array of validextensions
var fileName = file.name;
var fileNameExt = fileName.substr(fileName.lastIndexOf('.') + 1);
if ($.inArray(fileNameExt, validExtensions) == -1) {
return false;
}
This is only check for Extensions.Please Help me.
Posted
Updated 29-Mar-17 4:45am

1 solution

You'd have to check the binary of the file, but doing so in js is pointless as a malicious person can simply remove your javascript. Do that kind of checking on the server-side so it can't be circumvented.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900