How do I get the file extension from $image?
$image = file_get_contents($url);
It's much easier to do it using the filename.
Use getimagesize
($url)
. In particular, see index 2 of the resulting array.
You can't, you only have the contents. Get it from $url
instead if possible:
$extension = pathinfo($url, PATHINFO_EXTENSION);