Note $file_name_encrypted
will not contain a real or matchable extension, because your appending the filename with md5:
$file_name_encrypted = $file_name."".md5(rand(1, 1000000));
e.g filename.jpg79054025255fb1a26e4bc422aef54eb4
So it will never match any in your $allowedExts
array. Fix that then:
Change that line too:
$extension = pathinfo($file_name_encrypted, PATHINFO_EXTENSION);
Or explode then pass the exploded to the end() function.
$temp = explode(".", $file_name_encrypted);
$extension = end($temp);