How to filter user file uploads

How to filter user file uploads

I want to allow visitors to the website to upload their photos via a form. 
How can I make sure that any files uploaded are restricted to jpeg or png image files only.
ie: I need to ensure that no dangerous scripts and other non image documents are uploaded.