0

I am using http://otw.rets.interealty.com/Login.asmx/Login I am getting image as Binay Data. How can I display a binary data from RETS as an Image. Here is my code

$sysid = $data['sysid'];
$photos = $rets->GetObject("Property", "Photo", $sysid, "*", 1);
echo $photos[0]['Data'];
Minu
  • 3
  • 1

3 Answers3

0

I would look at the content-type of the results/data you get back. I would save each file with there respective type (.jpg, .bmp) then reference the saved file in you PHP code.

https://github.com/troydavisson/PHRETS/wiki/GetObject

dj_goku
  • 117
  • 6
0

According to the PHRETS documentation for GetObject, the last argument in GetObject, $location, can either be a "0" or "1". "1" returns the image's URL string and "0" returns the binary image data.

#1 Encoding the image data and outputting to browser without saving to a file. From this SO question

$photos = $rets->GetObject("Property", "Photo", $sysid, "*", 0);
foreach ($photos as $photo) 
{

    if ($photo['Success'] == true) 
    {
        $contentType = $photo['Content-Type'];
        $base64 = base64_encode($photo['Data']); 
        echo "<img src='data:{$contentType};base64," . $base64 . "' />";
    }
    else 
    {
        echo "({$photo['Content-ID']}-{$photo['Object-ID']}): {$photo['ReplyCode']} = {$photo['ReplyText']}<br />";
    }

}

#2 Saving the image to a file and then displaying it. From PHRETS

$photos = $rets->GetObject("Property", "Photo", $sysid, "*", 0);
foreach ($photos as $photo) 
{

    if ($photo['Success'] == true) 
    {
        file_put_contents("image-{$listing}-{$number}.jpg", $photo['Data']);
        echo "<img src='image-{$listing}-{$number}.jpg' />";
    }
    else 
    {
        echo "({$photo['Content-ID']}-{$photo['Object-ID']}): {$photo['ReplyCode']} = {$photo['ReplyText']}<br />";
    }

}
Community
  • 1
  • 1
Andrew Briggs
  • 1,329
  • 12
  • 26
  • I am using http://otw.rets.interealty.com Ottawa Real Estate Board. Do you know how to do pagination in this? "Limit" => "10" is working but "Offset" is not working – Minu Nov 02 '14 at 17:46
  • @Minu - Check with your RETS server as offset may not be supported by your RETS server. If my post answered your question please mark it as answered. – Andrew Briggs Nov 03 '14 at 00:44
  • Do you know how to use Unlimited Key Index in PHRETS? – Minu Nov 15 '14 at 04:02
0

There's some good information in these answers already.

To address your later question, the Interealty server does not support pagination. To use Key Index, you must:

1) use RETS/1.7.2 or later 2) specify Limit => NONE in your SearchRequest 3) give only key index identified fields in your Select parameter within the SearchRequest

If you get those 3 things right, the server should suspend its records-per-response limit.

troydavisson
  • 341
  • 1
  • 4