downloading images from webpages using php
<p>I am trying to create a PHP function that downloads images from a webpage that you put in as a parameter. However, the webpage itself though is a kind of gallery which only has very small thumbnail versions of the images, each linking directly to the larger full jpeg images that I want to download to my local computer. So the images will not downloaded directly from the webpage itself that I put into the function, but rather from the individual links to these jpeg image files on the webpage.</p>

<p>So for example:</p>

<pre><code>www.somesite.com/galleryfullofimages/
</code></pre>

<p>is the location of the image gallery,</p>

<p>and each jpeg image file from the gallery that I want is then located at something like:</p>

<pre><code>www.somesite.com/galleryfullofimages/images/01.jpg
www.somesite.com/galleryfullofimages/images/02.jpg
www.somesite.com/galleryfullofimages/images/03.jpg
</code></pre>

<p>What I've been trying to do so far is to use the <code>file_get_contents</code> function to get the full html of the webpage as a string, and then try to isolate all of the <code>&lt;a href="images/01.jpg"&gt;</code> elements inside the quotes and put them inside of an array. Then use this array to locate each image and download them all with a loop.</p>

<p>this is what I have done so far:</p>

<pre><code>&lt;?php

$link = "http://www.somesite.com/galleryfullofimages/";
$contents = file_get_contents($link);

$results = preg_split('/&lt;a href="[^"]*"/', $contents);

?&gt;
</code></pre>

<p>But I am stuck at this point. I am also totally new to regular expressions, which as you can see I tried to use. How can I isolate each image link and then download the image? Or is there a better way of doing this altogether? I have also read about using cURL. But I can't seem to implement that either. </p>

<p>I hope this all makes sense. Any help will be greatly appreciated.</p>
