Proper way to download photos?

889 views
Skip to first unread message

Chris Jackson

unread,
Dec 14, 2014, 4:47:51 PM12/14/14
to phr...@googlegroups.com
Hello all. I am new to the RETS experience (using PHRETS). I download all listing data each morning to my database with incremental updates throughout the day. When queries are performed on the website the data is then pulled from my database, which is quite fast. I gather that this is the common way of pulling/storing listing data.

My question is how should the photos be downloaded? The code below runs in my while loop every time a query is made on the website, downloading only the photos needed to my server and displaying them. Is this the common way to do it? It displays the photos but the delay is substantial, roughly 10-20 seconds every time.

I would assume that downloading every single photo for all listings (Thousands) each morning is terrible inefficient.


MySQL SELECT Statement (Pulling listings from my database)
While loop{...


  $photos
= $rets->GetObject("Property", "Photo", $Matrix_Unique_ID);
 
foreach ($photos as $photo) {
        $listing
= $photo['Content-ID'];
        $number
= $photo['Object-ID'];
 
       
if ($photo['Success'] == true) {
                file_put_contents
("IDX_images/image-{$listing}-0.jpg", $photo['Data']);    
       
}
       
else {
                echo
"({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
       
}
 
break;} //getting only one photo, image-{$listing}-0.jpg



...} End While loop


I appreciate any help thrown my way!

Chris Jackson

unread,
Dec 18, 2014, 6:07:28 PM12/18/14
to phr...@googlegroups.com
I am downloading the photos to my server in a batch rather than downloading them on the fly when needed. How is everyone downloading them? I am running the phrets getObject() and downloading the photos but I always get timed out. I am also setting set_time_limit(0); at the top of my PHP page but that doesn't seem to help.

Chris Farrugia

unread,
Dec 18, 2014, 6:37:57 PM12/18/14
to phr...@googlegroups.com
I really wish someone would respond to this. I'm in the same boat you're in. 

Sent from my iPhone

On Dec 18, 2014, at 6:07 PM, Chris Jackson <jackso...@gmail.com> wrote:

I am downloading the photos to my server in a batch rather than downloading them on the fly when needed. How is everyone downloading them? I am running the phrets getObject() and downloading the photos but I always get timed out. I am also setting set_time_limit(0); at the top of my PHP page but that doesn't seem to help.





I appreciate any help thrown my way!

--
You received this message because you are subscribed to the Google Groups "PHRETS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phrets+un...@googlegroups.com.
To post to this group, send email to phr...@googlegroups.com.
Visit this group at http://groups.google.com/group/phrets.
For more options, visit https://groups.google.com/d/optout.

Chris Jackson

unread,
Dec 18, 2014, 7:12:36 PM12/18/14
to phr...@googlegroups.com
I have been racking my brain for 4 days on this.

Chris Farrugia

unread,
Dec 18, 2014, 7:13:33 PM12/18/14
to phr...@googlegroups.com
Troy will probably chime in.  He’s very active in the group but I’m sure quite busy.

Troy Davisson

unread,
Dec 18, 2014, 8:16:00 PM12/18/14
to phr...@googlegroups.com

When you say it times out every time, does it actually always fail 100% of the time or will some requests succeed?  If you punch in your credentials and GetObject request into www.retsmd.com/view_photos.php , do you get the same timeout?

Chris Farrugia

unread,
Dec 22, 2014, 5:30:11 PM12/22/14
to phr...@googlegroups.com
Troy:

Do you have sample code (a function perhaps) to show how you download a listing's photos?

Chris Jackson

unread,
Dec 27, 2014, 2:16:40 PM12/27/14
to phr...@googlegroups.com
I am downloading all of the photos to the server, breaking them up and only downloading a chunk at a time. After a couple of minutes I get a blank screen with the following error. I have set_time_limit(0); set but that doesn't seem to do anything.

We're sorry! Something unexpected happened. Please let us know! If you wait a minute and refresh the page, everything should return to normal soon. 500



Chris Jackson

unread,
Dec 27, 2014, 2:30:10 PM12/27/14
to phr...@googlegroups.com
The following is my query. I am only trying to pull all photos from this month and still get the error.

$search = $rets->SearchQuery("Property","Listing","(PhotoModificationTimestamp=2014-12-01T00:00:00-2014-12-31T12:59:59)", array("Limit" => "100000") );

R.S. Harding

unread,
Feb 23, 2015, 12:02:45 PM2/23/15
to phr...@googlegroups.com
Troy, do you have the source code for view_photos.php?  I can get the images for Palm Beach MLS with that program, but my own program (which I've used for other MLS's) fails to get images with the basic call:

 {$photos = $rets->GetObject('Property', 'Photo', $sysid, "*", 1);}

I get:
    [ReplyCode] => 20403
    [ReplyText] => No such object available for this resource

For each call to get images

Troy Davisson

unread,
Feb 23, 2015, 4:35:50 PM2/23/15
to phr...@googlegroups.com
What is the value of your $sysid variable?

--

R.S. Harding

unread,
Feb 23, 2015, 4:50:21 PM2/23/15
to phr...@googlegroups.com
I figured out what the problem was.  The sysid's for Palm Beach MLS are 26 char fields!  I was using them as integers and I guess they were being converted to scientific notation.  When I cast them to strings, I was able to get the images.

Thanks for your help and for a great tool!



--
You received this message because you are subscribed to a topic in the Google Groups "PHRETS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phrets/Ur83LKUMlBc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phrets+un...@googlegroups.com.

Harshvir Singh Gurm

unread,
Mar 18, 2017, 6:09:30 PM3/18/17
to PHRETS
Hi Harding

Can you please tell me from where did you get the $sysid's? I am unable to locate it. I am using version 2.x and mostly the references over here are from version 1.x. 

William Spence

unread,
Mar 20, 2017, 4:14:53 PM3/20/17
to PHRETS
Troy, why do you have to download photos using getObject? I need more information for my database than just the photo address, so I tried to request all the information that I needed directly from the Media resource/Media class?  I tried the following code to download photo information from a time period of $date to $today:

$resource = 'Media';
$class = 'Media';
$fields = 'matrix_unique_id,MediaPath,ModifiedDate,Size,Table_MUI';

$listings = array();

$query = '(ModifiedDate='.$date.'T00:00:00.000-'.$today.'T23:59:59.000)';
$result = $rets->Search($resource, $class, $query, array('Select'=>$fields, "Format"=>"COMPACT-DECODED"));
$listings = $result->toArray();
echo count($listings)."\n";

foreach ($listings as $listing) {
    echo $listing['MediaPath']."\n";
}

I thought that this would echo the url for each photo, but it does not.  I can echo out any of the other fields that I requested, but the MediaPath field echos out as a blank.  Can you get photo URL's this way, or do you have to use the getObject method to do this?  The reason that I ask is I need a lot more information about each photo than just the URL.

Gennadiy Kofman

unread,
Mar 20, 2017, 5:39:45 PM3/20/17
to PHRETS
William,

The getObject method is often a way to get the media for a specific listing.  However, not all rets behave this way.  CRMLS for example doesn't have objects, but a separate Media class.  So what your doing is probably fine if you see the Media resource.  As for getting the url, I would try to var dump the $listing (instead of echo $listing['MediaPath']."\n";) and see what else is in there.  If you don't see what you need, you can contact your rets provider to see whats up.

William Spence

unread,
Mar 20, 2017, 8:47:29 PM3/20/17
to PHRETS
Thanks for the advice.  I did a var_dump as you recommended, and it gives me just about all the information that I want...except the URL!!! I can get the unique_id, the ModifiedDate, the OriginalFilename, the Size, and a host of other things, but the MediaPath is just an empty set of quotes.  Looks like I may have to contact my Rets provider.  I wonder if it has something to do with the Object Types for the Media resource?  The options are Photo and LargePhoto, and since I don't know how to set those values for a regular query as in the example in my previous post like you would with getObject, I wonder if it just does not give me the URL because I haven't specified exactly which photo object type that I want???

Does anyone know how to set the object type to Photo or LargePhoto when you are doing just a general query and not a getObject?

Gennadiy Kofman

unread,
Mar 21, 2017, 8:22:25 PM3/21/17
to PHRETS
This might be a longshot, but try to look at the contents of $result before you convert it to an array.  Maybe the object isn't converting correctly.  Also, remove $fields from the search query to make sure your seeing all the fields.

And no, object type is only available for objects.  For RETS that have a separate Media class, you would often find different fields for different sizes.  Or, there might be more then one entry for each image.  So one entry is large, one is xlarge, etc.So it really can depend on the RETS.

You never actually said what RETS your trying to pull.  Maybe someone has done it here and can help you.
Reply all
Reply to author
Forward
0 new messages