You are having a little trouble with your variable names in the following two lines of code -
$extensie = search_extenstion($name);
if (!in_array($extenstion, $filetypes)){
If you were developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini, php would help you by displaying all the errors it detects. You would save a TON of time. There would have been an undefined error message about the $extenstion variable (which is not spelled correctly anyway) since it is not the same variable name as what is being used in the line of code that is setting $extensie.