$typeok is set to true but then i check in switch statements if the file is in permitted formats if not i set $typeok to false.
This is not actually what is happening. Depending on what the user claims the file type is (not the same as what the file type really is), you either set a variable named
$src or change
$typeok to false. Neither action seems to have any purpose (unless you make some use of them later).
I don’t understand why is it too late. Where should i put it then?
It is “too late” because you have already saved the uploaded file. (So, really, why bother checking at all?) If you do check the file type (which, as described above, you are not effectively doing now), you would need to do so before saving the uploaded file.