1

How do I get the file extension from $image?

$image = file_get_contents($url);
4

2 回答 2

3

It's much easier to do it using the filename.

Use getimagesize($url). In particular, see index 2 of the resulting array.

于 2012-08-05T01:52:54.730 回答
2

You can't, you only have the contents. Get it from $url instead if possible:

$extension = pathinfo($url, PATHINFO_EXTENSION);
于 2012-08-05T01:51:57.780 回答