I have written this code:

$filename = "some/path/where/the/file/can/be/found.some_extension";
$buffer = file_get_contents($filename);
$finfo = new finfo(FILEINFO_MIME_TYPE);
var_dump($finfo->buffer($buffer));
finfo_close($finfo);

Possible outputs were of:

"image/jpeg", "image/png", "image/gif", "image/x-ms-bmp"

I would like to know, what are the possible outputs of $finfo->buffer($buffer), if the file is a png, gif, bmp, or jpg?

I have seen here a returnMIMEType function, which, for instance will not detect "image/x-ms-bmp" to be a bmp.

有帮助吗?

解决方案

We can view the possible MIME types of file extensions by searching for the file extension at the link provided by Pitchinnate. For instance BMP MIME types can be found at: filext.com/file-extension/BMP

其他提示

In this thread, you can find some useful suggestions and functions for your situation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top