What PHP function will give me the type of file?
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.
精彩评论