How do I regulate the fileupload function

eg I want people to upload a word.doc of a maximum file size of 30kb which generates an http_ref also. if the file size is bigger
then a message alert appears or a URL redirect
any ideas

Cheers