Since you need the server side, you can use the mime file type.
This post shows how to determine the MIME type based on the contents of the files (rather than the extension).
If you want to limit the input to the SPECIFIC file extension, you can simply check the input name for what you want to accept. If this goes away, you can do xref against the library in the message that I linked, to make sure that the user did not just change the file extension for you.
This will provide a fairly high degree of confidence that the file is the one you want to accept!
EDIT: Based on the comments so far .... Based on what you said, you are looking for this method that should work well for you. My suggestion is if you just want to limit it to the file types listed in one of your comments ... Do a simple check on the file extension. If this is the case, transfer the file to urlmon.dll specified in the link. Make sure that it is not returned as an invalid type. Aka executable file / java / zip / etc. If this is not an invalid type, then you will have a very high degree of confidence that it is a safe file!
Finally, after reading the comments on this post, it looks like urlmon.dll can support all types of files that you want implicitly, which saves you from having to check that it is not an executable file or something like that, but you will need to confirm so that doc / docx / xsl / xslx will return a valid mime type.
source share