Need Help saving all images present in a url to a folder
<p>This is not a duplicate question.Please go through it once.I am trying to save images present on <a href="http://www.nobroker.in" rel="nofollow noreferrer">http://www.nobroker.in</a>. Especially from:</p>

<blockquote>
  <p><a href="https://www.nobroker.in/property/rent/bangalore/Koramangala?nbPlace=ChIJLfyY2E4UrjsRVq4AjI7zgRY&amp;lat_lng=12.9279232,77.62710779999998&amp;radius=1.0&amp;sharedAccomodation=0&amp;orderBy=nbRank,desc&amp;radius=1&amp;pageNo=1" rel="nofollow noreferrer">https://www.nobroker.in/property/rent/bangalore/Koramangala?nbPlace=ChIJLfyY2E4UrjsRVq4AjI7zgRY&amp;lat_lng=12.9279232,77.62710779999998&amp;radius=1.0&amp;sharedAccomodation=0&amp;orderBy=nbRank,desc&amp;radius=1&amp;pageNo=1</a></p>
</blockquote>

<p>for the above search query there are paages from 1 to 18.I want to download the images from paage no 1 to 18 to a folder.I wrote the following script:</p>

<pre><code>&lt;?php

function scrapeImages($base,$html) 
{
    $dom = new domDocument;
    @$dom-&gt;loadHTML($html);

    //find all the images in the HTML
    $images = $dom-&gt;getElementsByTagName('img');
    $imgArray = array();

    //for each image tag, grab its src attribute and add it to the array
    $i=0;
    foreach ($images as $image) {
        echo $base.$image-&gt;getAttribute('src').'&lt;br&gt;';
        urltoimage($base.$image-&gt;getAttribute('src'));
        $i++;
    }

    return $i;
}

function urltoimage($image_link)
{
    //echo $image_link; die;
    if (@getimagesize($image_link)) {
        //$image_link ="https://www.dropbox.com/s/pt4wu5if3kwufr2/310890.jpg";
        $no = mt_rand(10000000, 99999999);
        $rand = $no."test".time();

        $split_image = pathinfo($image_link);

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL , $image_link);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
        $response = curl_exec ($ch);
        curl_close($ch);
        $updir= 'img';
        $filename= $rand.".jpg";
        $file_name = $updir.'/'.$filename;

        $file = fopen($file_name , 'w') or die("X_x");
        fwrite($file, $response);
        fclose($file);

        return $file_name;
    } else {
        return  'error';
    }
}

$base = 'https://www.nobroker.in/property/ajax/rent/';
$url = 'https://www.nobroker.in/property/rent/bangalore/Koramangala?nbPlace=ChIJLfyY2E4UrjsRVq4AjI7zgRY&amp;lat_lng=12.9279232,77.62710779999998&amp;radius=1.0&amp;sharedAccomodation=0&amp;orderBy=nbRank,desc&amp;radius=1&amp;pageNo=1'; 
$images1 = scrapeImages($base,file_get_contents($url));
echo $images1 .' Images found';
</code></pre>

<p>But getting only 2 images,instead of some 100+ images.</p>