具有PHRETS v2的属性照片文件
下面是我的php代码,它试图下载一个属性列表的所有照片。它成功地查询了RETS服务器,并为每张照片创建了一个文件,但该文件似乎不是一个功能映像。(矩阵要求下载文件,而不是URL。) 下面的照片列表表明它成功地查询了一个列表id(47030752)中存在的所有照片(本例中为20张照片)。在web浏览器中,文件仅在黑色背景上显示为一个小的白色正方形:例如()。与真实照片相比,文件大小(4)似乎也非常小具有PHRETS v2的属性照片文件,phrets,Phrets,下面是我的php代码,它试图下载一个属性列表的所有照片。它成功地查询了RETS服务器,并为每张照片创建了一个文件,但该文件似乎不是一个功能映像。(矩阵要求下载文件,而不是URL。) 下面的照片列表表明它成功地查询了一个列表id(47030752)中存在的所有照片(本例中为20张照片)。在web浏览器中,文件仅在黑色背景上显示为一个小的白色正方形:例如()。与真实照片相比,文件大小(4)似乎也非常小 du -s PHOTO* 4 PHOTO-47030752-10.jpg 4 PHOTO-
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?>
这个脚本中可能有一些部分在实际生产中不起作用,但足以进行测试。此脚本似乎成功地从RETS服务器查询所需的信息。问题只是创建的实际文件似乎不是功能性照片
提前感谢!:) 您的代码示例是官方文档和可用实现的混合体。这一行的问题在于: $object->setContent(文件获取内容($object->getLocation())
你应该把它完全去掉。这实际上是在您有机会将内容保存到文件之前,覆盖您下载的图像。删除该选项后,它将按预期工作。对此没有建议吗?我正在连接到佐治亚州亚特兰大市(FMLS)的RETS系统,该系统不提供照片URL,但允许下载图像文件。是否没有人使用PHRETS v2成功下载了财产清单照片?优秀!谢谢你提供的信息。我还需要使用$photo=$object->getContent();变量,但这些更改的组合起作用。非常感谢你!
file_put_contents("/bigdirs/fmls_pics/PHOTO-{$listing}-{$number}.jpg", "$object->getContent();");