Finding Extension of uploaded file (PHP)
PhpFilePhp Problem Overview
Can We find out the extension of the original file from $_FILES["file"]["tmp_name"]
? For example jpg or png etc?
Php Solutions
Solution 1 - Php
$name = $_FILES["file"]["name"];
$ext = end((explode(".", $name))); # extra () to prevent notice
echo $ext;
Solution 2 - Php
You could use pathinfo()
:
$path_parts = pathinfo($_FILES["file"]["name"]);
$extension = $path_parts['extension'];
Solution 3 - Php
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 4 - Php
Yes, assuming it's accurately named. It will retain its original name and extension.