You have this line. It is returning the image URL, not the binary image data.
$photos = $rets->GetObject("Property", "Photo", $record[$fo], "*", 1);
The fifth argument should be a 0.
$photos = $rets->GetObject("Property", "Photo", $record[$fo], "*", 0);
According to the PHRETS documentation, a 1 returns the image URL and a 0 returns the binary image data.