在PHPRETS中下载媒体对象

时间:2015-07-29 23:41:00

标签: php media rets

背景资料

  • 我想使用PHPRETS下载特定属性的照片。
  • 我的PHPRETS配置可成功下载属性数据。问题仅在于下载媒体文件。
  • 我可以使用Windows应用程序RETS Connector下载该属性的照片,这意味着图像存在。
  • 我作为对象键传递的值(N3273704)是我从KeyField获得的值(ml_num)

关键字段

ml_num

我运行的代码

$photos = $rets->GetObject("Property", "Photo", "N3273704", "*", 0);

var_dump($photos);

foreach ($photos as $photo) {
    $listing = $photo['Content-ID'];
    $number = $photo['Object-ID'];

    if ($photo['Success'] == true) {
        file_put_contents("image-{$listing}-{$number}.jpg", $photo['Data']);
    } else {
         echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
    }
}

原始标题和回复

[2015-07-29 13:16:09] PHRETS.DEBUG: Sending HTTP Request for http://rets.torontomls.net:6103/rets-treb3pv/server/getobject (GetObject) {"query":{"Resource":"Property","Type":"Photo","ID":"N3273704:*","Location":0},"headers":{"User-Agent":"PHRETS/2.0","RETS-Version":"RETS/1.5","Accept-Encoding":"gzip"},"cookies": ..."]} []
[2015-07-29 13:16:09] PHRETS.DEBUG: Response: HTTP 200 [] []

屏幕输出(var_dump的结果)

array(20) {
[0]=>
object(PHRETS\Models\Object)#32 (10) {
  ["content_type":protected]=>
  string(8) "text/xml"
  ["content_id":protected]=>
  string(4) "null"
  ["object_id":protected]=>
  string(4) "null"
  ["mime_version":protected]=>
  NULL
  ["location":protected]=>
  NULL
  ["content_description":protected]=>
  NULL
  ["content_sub_description":protected]=>
  NULL
  ["content":protected]=>
  string(192) "<?xml version="1.0" standalone="no"?>
<!DOCTYPE RETS SYSTEM "RETS-20041001.dtd">
<RETS ReplyCode="20403" ReplyText="No Object Found: No matching object was found to satisfy the request."/>"
  ["preferred":protected]=>
  NULL
  ["error":protected]=>
  object(PHRETS\Models\RETSError)#45 (2) {
    ["code":protected]=>
    int(20403)
    ["message":protected]=>
    string(69) "No Object Found: No matching object was found to satisfy the request."
  }
}
[1]=> ...

2 个答案:

答案 0 :(得分:1)

我能够弄清楚这个问题,我写这篇文章是希望能节省一些时间。

在监控HTTP流量并比较从PHRETS和RETS连接器(Windows应用程序)发送的原始标头后,发现一些RETS服务器(在这种情况下,多伦多房地产委员会)需要&#34;接受&#34;要在标题中出现的字段。因此,通过将以下行添加到Session类的构造函数来解决问题:

'Accept' => '*/*',

答案 1 :(得分:0)

我想提供一个注释...... TREB错误配置了KeyField。他们正在使用Property的标识字段(ml_num)的DBName版本,而KeyField应该是该字段的SystemName版本(Ml_num)....只是在案例上有所不同,但足以对于将从RETS元数据自动派生KeyField的RETS客户端来说,这是一个重大变化。