属性 PHRETS v2 的照片文件

Property Photo Files with PHRETS v2

下面我的 php 代码尝试下载 属性 列表的所有照片。它成功地查询了 RETS 服务器,并为每张照片创建了一个文件,但该文件似乎不是功能图像。 (MATRIX 需要下载文件,而不是 URL。)

下面的照片列表表明它成功查询了一个列表 ID (47030752) 以获取所有存在的照片(在本例中为 20 张照片)。在网络浏览器中,文件仅显示为黑色背景上的白色小方块:例如(https://photos.atlantarealestate-homes.com/photos/PHOTO-47030752-9.jpg)。与真实照片相比,文件大小 (4) 似乎也很小。

du -s PHOTO*
4   PHOTO-47030752-10.jpg
4   PHOTO-47030752-11.jpg
4   PHOTO-47030752-12.jpg
4   PHOTO-47030752-13.jpg
4   PHOTO-47030752-14.jpg
4   PHOTO-47030752-15.jpg
4   PHOTO-47030752-16.jpg
4   PHOTO-47030752-17.jpg
4   PHOTO-47030752-18.jpg
4   PHOTO-47030752-19.jpg
4   PHOTO-47030752-1.jpg
4   PHOTO-47030752-20.jpg
4   PHOTO-47030752-2.jpg
4   PHOTO-47030752-3.jpg
4   PHOTO-47030752-4.jpg
4   PHOTO-47030752-5.jpg
4   PHOTO-47030752-6.jpg
4   PHOTO-47030752-7.jpg
4   PHOTO-47030752-8.jpg
4   PHOTO-47030752-9.jpg

我正在使用的脚本:

#!/usr/bin/php

<?php

date_default_timezone_set('this/area');

require_once("composer/vendor/autoload.php");

$config = new \PHRETS\Configuration;

$config->setLoginUrl('https://myurl/login.ashx')
        ->setUsername('myser')
        ->setPassword('mypass')
        ->setRetsVersion('1.7.2');

$rets = new \PHRETS\Session($config);

$connect = $rets->Login();

$system = $rets->GetSystemMetadata();

$resources = $system->getResources();
$classes = $resources->first()->getClasses();

$classes = $rets->GetClassesMetadata('Property');

$host="localhost";
$user="db_user";
$password="db_pass";
$dbname="db_name";
$tablename="db_table";

$link=mysqli_connect ($host, $user, $password, $dbname);

$query="select mlsno, matrix_unique_id, photomodificationtimestamp from fmls_homes left join fmls_images on (matrix_unique_id=mls_no and photonum='1') where photomodificationtimestamp <> last_update or last_update is null limit 1";

print ("$query\n");
$result= mysqli_query ($link, $query);
$num_rows = mysqli_num_rows($result);

print "Fetching Images for $num_rows Homes\n";

while ($Row= mysqli_fetch_array ($result))  {
$matrix_unique_id="$Row[matrix_unique_id]";

$objects = $rets->GetObject('Property', 'LargePhoto', $matrix_unique_id);

foreach ($objects as $object) {
    // does this represent some kind of error
    $object->isError();
    $object->getError(); // returns a \PHRETS\Models\RETSError

    // get the record ID associated with this object
    $object->getContentId();

    // get the sequence number of this object relative to the others with the same ContentId
    $object->getObjectId();

// get the object's Content-Type value
    $object->getContentType();

    // get the description of the object
    $object->getContentDescription();

    // get the sub-description of the object
    $object->getContentSubDescription();

    // get the object's binary data
    $object->getContent();

    // get the size of the object's data
    $object->getSize();

    // does this object represent the primary object in the set
    $object->isPreferred();

    // when requesting URLs, access the URL given back
    $object->getLocation();

    // use the given URL and make it look like the RETS server gave the object directly
    $object->setContent(file_get_contents($object->getLocation()));

        $listing = $object->getContentId();
        $number = $object->getObjectId();
        $url = $object->getLocation();
        //$photo = $object->getContent();
        $size = $object->getSize();
        $desc = $object->getContentDescription();

if ($number >= '1') {

file_put_contents("/bigdirs/fmls_pics/PHOTO-{$listing}-{$number}.jpg", "$object->getContent();");

print "$listing - $number - $size $desc\n";

} //end if

} //end foreach

} //end while
mysqli_close ($link);

fclose($f);

php?>
                                                                                                         

对于将照片捕获到创建的文件中,是否有任何建议的更改?此命令创建照片文件:

file_put_contents("/bigdirs/fmls_pics/PHOTO-{$listing}-{$number}.jpg", "$object->getContent();");

此脚本的某些部分可能无法在现场制作中使用,但足以进行测试。这个脚本似乎成功地从 RETS 服务器查询了所需的信息。问题很简单,实际创建的文件似乎不是功能照片。

提前致谢! :)

您的代码示例混合了官方文档和可用的实现。问题出在这一行:

$object->setContent(file_get_contents($object->getLocation()));

你应该把它完全去掉。在您有机会将内容保存到文件之前,这实际上会覆盖您下载的图像。删除后,它应该可以按预期工作。