开发者

ASP.NET File upload - Validation

开发者 https://www.devze.com 2022-12-14 09:02 出处:网络
In our application , we are using asp.netFileUpload control to upload files. Requirement is , user should be able to upload only \".doc, .xls , .pdf\" files.

In our application , we are using asp.net FileUpload control to upload files.

Requirement is , user should be able to upload only ".doc, .xls , .pdf" files.

System should not allow him to upload other files. To achieve this we are validating the extension of the uploaded file. If it is not valid then throwing error message.. this works fine..

But if i change the any 开发者_JS百科exe file as .doc file , then system is allowing to upload. this should not happen.

Is there any way to validate the file with its content instead of its extension ..?


Check out this question/answer on stackoverflow. I belive this is a duplicate question.

Also, look into reading a file's magic number especially if you are just trying to determine if the file is one of a few acceptable types. Magic number Wikipedia


Uploadify is a good file uploading tool that I have found which allows you to specify which extensions you allow the user to see when uploading their files. It also has alot of other cool options and it is highly customizeable. It uses a combination of jquery and flash to allow the user to upload more than one file at a time as well (if desired).

0

精彩评论

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