You've got two options. I'm assuming 'upload' will hold the image name.
1) Use the server (i.e. PHP)
$extension = substr($_GET['upload' ],strrpos($_GET['upload'],"."));
2) Use the client (i.e. Javascript)
var ext = upload.value.substr(upload.value.lastIndexOf("."));
And then check if the extension equals ".gif" or ".jpg"