开发者

What PHP function will give me the type of file?

开发者 https://www.devze.com 2023-02-05 13:45 出处:网络
I\'m getting a file with \"file_get_contents\", there is any PHP Function that will 开发者_JAVA技巧give me the type of the file? In this example \"jpg\".

I'm getting a file with "file_get_contents", there is any PHP Function that will 开发者_JAVA技巧give me the type of the file? In this example "jpg".

$imagedata = file_get_contents("/path/to/image.jpg");      

Please give me some clues.

Best Regards,


You can use pathinfo like this:

$extension = pathinfo($filename, PATHINFO_EXTENSION); // jpg

Note that since this fetch the extension from the filename, it can easily be manipulated. You should use a function like getimagesize to determine if a file is a real image.


The word you are looking for is extension.

$ext = pathinfo($file, PATHINFO_EXTENSION);

This is an exact duplicate of How to extract a file extension in PHP? though, try searching a bit better next time.

0

精彩评论

暂无评论...
验证码 换一张
取 消