What are the drawbacks of the script's method of determining file types based on extensions?
The main drawback of determining file types based on extensions is that it can be easily manipulated by changing the file extension. To solve this issue, we can use the PHP function `finfo_file()` which uses file magic numbers to determine the file type, providing a more reliable method of identifying file types.
// Get file type using fileinfo
$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
$fileType = finfo_file($fileInfo, $filePath);
finfo_close($fileInfo);
echo "File type: " . $fileType;