Reputation: 106
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
Upvotes: 0
Views: 1904
Reputation: 26
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.
Upvotes: 1
Reputation: 236
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).
Upvotes: 0