Giving the fact that Apache is the most used web server out there, one way to achieve such thing is by using the powerfull mod_security. Mod_Security has option, where you can tell it to scan certain uploaded files and decide if this is malicious or not.