mattspriggs28 Posted October 14, 2010 Share Posted October 14, 2010 I'm wanting to extract an image from an external website and save to a location on my web server automatically. The scenario: 1. A user has an order form on our website with a field to paste the URL of a website in; 2. The user visits an external website page, which includes an image; 3. The user copies the URL out of the address bar, goes back to our website and pastes the link into the order form; 4. The user clicks next, and this extracts the image from the external website and uploads it to our website so the image can be seen alongside the order. My questions are: a. Can this be done? b. If it can't physically download the image and copy to my web server, can I read the html source of the external website and grab the full URL to use to show the image on my website? Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/215857-extracting-an-image-from-a-website/ Share on other sites More sharing options...
litebearer Posted October 14, 2010 Share Posted October 14, 2010 Quick answer is, yes can be done. Potential problem - if page has several images, which does he want? Link to comment https://forums.phpfreaks.com/topic/215857-extracting-an-image-from-a-website/#findComment-1122122 Share on other sites More sharing options...
mattspriggs28 Posted October 14, 2010 Author Share Posted October 14, 2010 That was going to be my next question, but I guess I could look for a specific string pattern in the img src to ensure I'm grabbing the correct image? Link to comment https://forums.phpfreaks.com/topic/215857-extracting-an-image-from-a-website/#findComment-1122123 Share on other sites More sharing options...
BlueSkyIS Posted October 14, 2010 Share Posted October 14, 2010 a. Sometimes. However, more servers are using protection to avoid having scripts download images. You'll need to emulate a browser well to make it more reliable. b. Sometimes. Again, some servers will not serve an image to an external source unless various restrictions are met. For instance, my server will not serve images unless the referrer is my server. I could hack around that using curl, but most people wouldn't know or bother. Link to comment https://forums.phpfreaks.com/topic/215857-extracting-an-image-from-a-website/#findComment-1122124 Share on other sites More sharing options...
mattspriggs28 Posted October 14, 2010 Author Share Posted October 14, 2010 OK, so I've now worked out how to extract the HTML from an external website. Now what I want to do is find a specific string or part of the URL in the page: 1. I want to find a string in the code that contains 'http://www.mysite.com/products/images/' 2. My code has found <img src="http://www.mysite.com/products/images/123.jpg" alt=""> So now what I want to do is grab the whole URL of the image, so everything after 'src="' and before '" alt="">'. Can someone please advise the easiest way to do this? Thanks. Link to comment https://forums.phpfreaks.com/topic/215857-extracting-an-image-from-a-website/#findComment-1122144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.