Mokariya Sanjay
Mokariya Sanjay

Reputation: 194

PHP get image extension from url?

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.

Upvotes: 4

Views: 4321

Answers (1)

Aleksandar Jakovljevic
Aleksandar Jakovljevic

Reputation: 941

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

Upvotes: 2

Related Questions