title: Downloading images from rets feed using phprets
body: <p>I am trying to use PHPRETS to download RETS FEED Data and Images, I am successful in downloading data as CSV but, though images are created in the image folder properly, the size of each image is zero. I am attaching the code I am using here, please help me so that I can download images properly.</p>
  
  <pre><code>    &lt;?php
  
      $rets_login_url = "http://retsgw.flexmls.com:80/rets2_0/Login";
      $rets_username = "**********";
      $rets_password = "**********";
  
     // use http://retsmd.com to help determine the SystemName of the DateTime field which
     // designates when a record was last modified
     $rets_modtimestamp_field = "LIST_87";
  
     // use http://retsmd.com to help determine the names of the classes you want to pull.
     // these might be something like RE_1, RES, RESI, 1, etc.
     $property_classes = array("B");
  
     // DateTime which is used to determine how far back to retrieve records.
     // using a really old date so we can get everything
      $previous_start_time = "1980-01-01T00:00:00";     require_once("lib/phrets.php");
  
     // start rets connection
     $rets = new phRETS;
  
     // only enable this if you know the server supports the optional RETS feature called 'Offset'
      $rets-&gt;SetParam("offset_support", true);
  
      echo "+ Connecting to {$rets_login_url} as {$rets_username}&lt;br&gt;\n";
      $connect = $rets-&gt;Connect($rets_login_url, $rets_username, $rets_password);
  
      if ($connect) {
      echo "  + Connected&lt;br&gt;\n";
      }
      else {
        echo "  + Not connected:&lt;br&gt;\n";
      print_r($rets-&gt;Error());
      exit;
      }
  
      foreach ($property_classes as $class) {
  
      echo "+ Property:{$class}&lt;br&gt;\n";
  
      $file_name = strtolower("property_{$class}.csv");
      $fh = fopen($file_name, "w+") or die("Can't open file");
  
      $fields_order = array();
  
      $query = "({$rets_modtimestamp_field}={$previous_start_time}+)";
  
      // run RETS search
      echo "   + Resource: Property   Class: {$class}   Query: {$query}&lt;br&gt;\n";
      $search = $rets-&gt;SearchQuery("Property", $class, $query, array('Limit' =&gt; 1000));
      $get_id = $_REQUEST['LIST_1'];
      if ($rets-&gt;NumRows($search) &gt; 0) {
  
              // print filename headers as first line
              $fields_order = $rets-&gt;SearchGetFields($search);
              fputcsv($fh, $fields_order);
  
              // process results
              while ($record = $rets-&gt;FetchRow($search)) {
                      $this_record = array();
                      foreach ($fields_order as $fo)  {
  
      if ($fo == 'LIST_1') {
  
          $photos = $rets-&gt;GetObject("Property", "Photo", $record[$fo], "*", 1);
  
          foreach ($photos as $photo) {
  
              if ($photo['Success'] == true) {
  
                   file_put_contents("photos/{$photo['Content-ID']}-{$photo['Object-ID']}.jpg", $photo['Data']);   
  
              }   
          }
      }
    $this_record[] = $record[$fo];
  }                           
      fputcsv($fh, $this_record);    
              }
  
      }
  
      echo "    + Total found: {$rets-&gt;TotalRecordsFound($search)}&lt;br&gt;\n";
  
      $rets-&gt;FreeResult($search);
  
      fclose($fh);
  
      echo "  - done&lt;br&gt;\n";
  
      }
  
      echo "+ Disconnecting&lt;br&gt;\n";
      $rets-&gt;Disconnect();
      ?&gt;
  </code></pre>