I have a findtexts function in PHP to get the extension of a file uploaded, and it's not working. If I echo $ext I get nothing.

```
if (isset($_POST['submit'])) 
{ 
if ($_POST['mainfile'] != "") 
{   
    function findexts ($filename) 
    { 
        $filename = strtolower($filename) ; 
        $exts = preg_split("%[/\\\\.]%", $filename);
        $n = count($exts)-1; 
        $exts = $exts[$n]; 
        return $exts; 
    } 

    //This applies the function to our file  
    $ext = findexts ($_FILES['mainfile']['name']) ; 
    $ran = rand () ;
    $ran2 = $ran.".";
    $target = $pid."_main_".$ran2.$ext; 
    $ok=1; 

     echo "ext= " .$ext;
     echo "<br>target = " .$target;

} 

}

```