0

I am trying to download images from new RETS CRMLS

$photos = $rets->SearchQuery("Media","Media",$lid, array('Limit' => 'none', 'Select' => "MediaOrder,MediaURL"));
foreach ($photos as $photo)
{
  if ($photo['Success'] == true)
  {
    file_put_contents("../images/{$photo['Content-ID']}-{$photo['Object-ID']}.jpg", $photo['Data']);
    $count++;
  }   
}

this is not working

Kypros
  • 2,997
  • 5
  • 21
  • 27
Azaz Khan
  • 106
  • 1
  • 6
  • How is it "not working"? What do you expect, and what happens instead? – Andrew Oct 31 '14 at 18:01
  • To download photos use GetObject() not SearchQuery(). Consult the PHRETS documentation under Usage Examples: https://github.com/troydavisson/PHRETS/wiki/GetObject#usage-examples – Andrew Briggs Nov 01 '14 at 22:00

2 Answers2

1

If you want to download the images from the Property class, you can use this rets function

$rets->GetObject("Property", "Photo", $listingId, "*", 1);

This will return the array of images associated with the particular listingId as image url.

If you want to download as binary image files then you can use the last parameter as '0', instead of '1'. [ '1' is for getting public image Urls]

If the image is to be downloaded from the Media class then you can use the same function with Media as the class. And you should first get the listing Id from the Property class.

Doml The-Bread
  • 1,761
  • 1
  • 11
  • 17
tweety
  • 26
  • 1
0

Your "file_put_contents" function appears to be attempting to parse the info headers within a multipart/mime response from a GetObject query. Rather, you'd want to do a straight http download of the MediaUrls. I'm not a php wizard, but you'd do something more like:

 $photoUrls = $rets->SearchQuery("Media","Media",$lid, array('Limit' => 'none', 'Select' => "MediaOrder,MediaURL"));

 while ($photo = $rets->FetchRow($photoUrls)) {

    file_put_contents("../images/{$lid}-{$photo['MediaOrder']}.jpg", file_get_contents($photo['MediaURL']));

  }   

 $rets->FreeResult($photoUrls);

Also, you probably want to limit your search to MediaTypes of "Image" so you don't get other binary data or documents, like virtual tour URLs or PDFs (see google group for this MLS that you also posted within).

TonyM
  • 236
  • 1
  • 8
  • What is the keyword for a listingID in CRMLS? They have like no documentation and it is very difficult to know what keywords of keys themselves are needed in order to do a search. – Nick Jun 13 '18 at 18:06