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 Quote Link to comment 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" /> Quote Link to comment 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'); Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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.