'Finding Extension of uploaded file (PHP) [duplicate]

Can We find out the extension of the original file from $_FILES["file"]["tmp_name"] ? For example jpg or png etc?



Solution 1:[1]

You could use pathinfo():

$path_parts = pathinfo($_FILES["file"]["name"]);
$extension = $path_parts['extension'];

Solution 2:[2]

Yes you can use $_FILES['file']['name'] to get the original name of the uploaded file. Just keep in mind that the extension may not always represent the real contents of the file.

Solution 3:[3]

Yes, assuming it's accurately named. It will retain its original name and extension.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Ballinger
Solution 2 GWW
Solution 3 thf