How can one determine the MIME type of a file in PHP 5.5?
To determine the MIME type of a file in PHP 5.5, you can use the `finfo_open` and `finfo_file` functions. `finfo_open` creates a new fileinfo resource and `finfo_file` returns the MIME type of the file. This allows you to accurately determine the MIME type of a file in PHP.
// Create a new fileinfo resource
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// Get the MIME type of a file
$mime_type = finfo_file($finfo, 'path/to/your/file.jpg');
// Close the fileinfo resource
finfo_close($finfo);
// Output the MIME type
echo $mime_type;
Related Questions
- How can the error message "MySQL-Error: No Database Selected" be resolved when trying to connect to a database in PHP?
- How can the logic for deriving status values from radio button values be efficiently implemented in PHP scripts?
- What are some common security measures that should be implemented when using PHP for VPN authentication?