gingle Posted March 12, 2009 Share Posted March 12, 2009 Hi, I'm trying to download an image from a safe url. Im using a service caller snapcasa which creates thumbnails from an url. I'd like to download this image but as you can see on this url, there isnt a jpeg extenson. How can I do it with php example: http://snapcasa.com/get.aspx?code=4824&size=l&url=www.google.ca Link to comment https://forums.phpfreaks.com/topic/149071-solved-get-image-from-url/ Share on other sites More sharing options...
rhodesa Posted March 12, 2009 Share Posted March 12, 2009 do you always know it will be a JPG? <?php $url = 'http://snapcasa.com/get.aspx?code=4824&size=l&url=www.google.ca'; copy($url,'images/new.jpg'); ?> <img src="images/new.jpg" /> Link to comment https://forums.phpfreaks.com/topic/149071-solved-get-image-from-url/#findComment-782906 Share on other sites More sharing options...
centenial Posted March 12, 2009 Share Posted March 12, 2009 Alternatively, if you can't guarantee that the image will be a JPEG, you can try: // get the contents of the image $imageData = file_get_contents('http://snapcasa.com/get.aspx?code=4824&size=l&url=www.google.ca'); // create the image resource $imageResource = imagecreatefromstring($imageData); // save the image to disk imagejpeg($imageResource,'image.jpg'); Link to comment https://forums.phpfreaks.com/topic/149071-solved-get-image-from-url/#findComment-782926 Share on other sites More sharing options...
rhodesa Posted March 12, 2009 Share Posted March 12, 2009 you can also get the content type from getimagesize() then determine the proper extension from that Link to comment https://forums.phpfreaks.com/topic/149071-solved-get-image-from-url/#findComment-782928 Share on other sites More sharing options...
gingle Posted March 12, 2009 Author Share Posted March 12, 2009 Yhks a lot guys, it's working! Link to comment https://forums.phpfreaks.com/topic/149071-solved-get-image-from-url/#findComment-783393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.