I’m using the following to detect an EXTERNAL image’s extension:
$url = (POST_IMAGESELECTOR);
$path_parts = pathinfo($url);
$extension = $path_parts['extension'];
All images come from various external sources. The sample above works 80% of the time, however, it fails when I run into an image without a traditional extension. An example would be the image located here:
http://media.kohls.com.edgesuite.net/is/image/kohls/227522?wid=1000&hei=1000&op_sharpen=1
What would the extension be on an image like this? How can I return the true extension?
Thanks!
If you’re sure that the file in question actually is an image then you could use getimagesize() or exif_imagetype() to determine the type of image you’re working with. You can then map that onto the appropriate filename extension.
Be careful though, you can’t be sure what will happen if you call these functions on files that aren’t images.