What's the best way/practice to get the extension of a uploaded file in PHP

Posted by Roland on Stack Overflow See other posts from Stack Overflow or by Roland
Published on 2011-01-04T07:46:35Z Indexed on 2011/01/04 7:53 UTC
Read the original article Hit count: 201

Filed under:

I have a form that allow users to upload files, I however need to get the file extension, which I am able to get, but not sure if I'm using the most effective solution

I can get it using the following ways

$fileInfo = pathinfo($_FILES['File']['name']);
echo $fileInfo['extension'];

$ext = end(explode('.',$_FILES['File']['name']));
echo $ext;

Which method is the best to use or are there even better solutions that would get the extension?

© Stack Overflow or respective owner

Related posts about php