I think that the best would be store the files on another server, but i can't do it, so i made this simple code to check the file extension and also i used getimagesize():
pastebin.com/raw/6FaH18He I know that's not enough, but i also disabled execution of scripts inside the upload folder with a .htaccess rule