开发者

JavaScript validation for invalid file type

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 tha开发者_如何学运维t this is an invalid file?


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

You have to handle this check server side.


There is no way doing it using JavaScript.


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") )
    {
        ....
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜