To limit the file types, use Server Validation. Select the File Extension validation type.
For the 500 error, add the following code at line 1 to turn on error reporting, this should return the actual error:
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
?>
once we know the real error, we can troubleshoot.
NOTE: in the future, pleases don't paste the page code in your message, instead, attach the php file.