Jump to content

[SOLVED] Save image from URL to images field in repeater via API


Tyssen
 Share

Recommended Posts

I'm working with an XML feed which provides image URLs that I want to save to an images field in a repeater. So far I have this:

foreach($page->goodreads as $goodreads) :

  $xml_string = $cache->get($goodreads->isbn, 3600, function() use($goodreads_api, $goodreads) {
    return curl_get_contents('https://www.goodreads.com/search/index.xml?key='.$goodreads_api.'&q='.$goodreads->isbn);
  });
  $book_xml = new SimpleXMLElement($xml_string);

  foreach ($book_xml->search->results->work as $book) :

    $goodreads->of(false);
    $goodreads->images->add($book->best_book->image_url);
    $goodreads->save();
    $goodreads->of(true);

  endforeach;

endforeach;

I've tested that $book->best_book->image_url does actually return a value and have also tested the above with a hard-coded image URL but in both cases, no image is saved. What am I missing?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...