pleek Posted June 16, 2009 Share Posted June 16, 2009 ok, so i know how to get the images extension if its a direct path to the image. My problem is my script will be using file paths such as.. http://www.tinyportal.net/index.php?action=dlattach;attach=18707;type=avatar How can i get that files extension? Quote Link to comment https://forums.phpfreaks.com/topic/162455-getting-an-images-extension-from-a-url/ Share on other sites More sharing options...
bibliovermis Posted June 16, 2009 Share Posted June 16, 2009 Cut on the question mark and then cut on the last period. $ext=array_pop(explode('.',array_shift(explode('?',$url)))); Quote Link to comment https://forums.phpfreaks.com/topic/162455-getting-an-images-extension-from-a-url/#findComment-857501 Share on other sites More sharing options...
Mark Baker Posted June 16, 2009 Share Posted June 16, 2009 parse_url() Quote Link to comment https://forums.phpfreaks.com/topic/162455-getting-an-images-extension-from-a-url/#findComment-857509 Share on other sites More sharing options...
pleek Posted June 17, 2009 Author Share Posted June 17, 2009 Quote 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. Quote parse_url() I read the php manual for parse_url and im not seeing how that will get the files extension. Quote Link to comment https://forums.phpfreaks.com/topic/162455-getting-an-images-extension-from-a-url/#findComment-857714 Share on other sites More sharing options...
xphoid Posted June 17, 2009 Share Posted June 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162455-getting-an-images-extension-from-a-url/#findComment-857742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.