Jump to content

Getting an images extension from a url


pleek

Recommended Posts

Cut on the question mark and then cut on the last period.

 

$ext=array_pop(explode('.',array_shift(explode('?',$url))));

Won't that show php as the filetype? The file itself is a png image.

 

parse_url()

 

I read the php manual for parse_url and im not seeing how that will get the files extension.

You won't be able to get the image's file extension from that URL simply because it's not there.

 

If the script is on your server you could somehow find the source image the same way the script does and get the file extension/type that way.

 

As a lazy/bad alternative you could use getimagesize() on the URL along with image_type_to_extension() to find the image's extension/type.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.