4

Image url like below.

$url = https://lh3.googleusercontent.com/-4T303dPCnp0ZnkzQjSIjeB7k8L_DiQglhUgNqXM-OkeLQXoNwwFnzM1MoFjJGw7DGI=w300

How to get extension from this url.

I m using pathinfo to get extension but it's not work

$ext = pathinfo($destinationPath.$filename, PATHINFO_EXTENSION);

Anyone help me to get image extension from url.

Mokariya Sanjay
  • 194
  • 3
  • 13

1 Answers1

2

pathinfo just parses a path, you can't use it in this context, when path doesn't have extension in it. You need to assign extension based on mime type.

So, first, get mime type, like here: https://stackoverflow.com/a/12023961/1059672 Then, assign extension based on mime type, like here: https://stackoverflow.com/a/16511092/1059672