I'm using version 2 of PHRETS and while looping through Listing ID's I need to download images. Not all listings have images. In the previous version 1 there was an option for if ($photo['Success'] == true)
Here is my php code in a function. I've noted that getContentType() will display application/xml; charset=utf-8 for listings that do not have images and image/jpeg for ones that do. Also, $photos->first()->getObjectId(); will be blank for listings with no images. Given this info I presume I can write a simple conditional to check. But my question is, is there any official way to do this?
function downloadImages($ListingKey,$rets){
$photos = $rets->GetObject('Property','Photo',$ListingKey);
echo $photos->first()->getContentId();
echo $photos->first()->getObjectId();
echo $photos->first()->getContentType();
echo $photos->first()->getContentDescription();
echo $photos->first()->getContentSubDescription();
echo $photos->first()->getSize();
echo $photos->first()->isPreferred();
echo $photos->first()->getLocation();
}
This is my current conditional check
function downloadImages($listingKey,$rets){
$photos = $rets->GetObject('Property','Photo',$listingKey);
if($photos->first()->getContentType()=='image/jpeg'){
mkdir('/home/server/public_html/img/'.$listingKey,0777);
foreach ($photos as $p) {
file_put_contents('/home/server/public_html/img/'.$listingKey.'/'.$p->getContentId().'-'.$p->getObjectId().'.jpg',$p->getContent());
}
}
}