Jump to content
cabrooney

setAndSave() to Single Image Field

Recommended Posts

I save an Image from an URL to an image field using setAndSave().
The image field is set to "Single Item (0 if empty)" and "Maximum Files Allowed = 1".

But the line

$page->setAndSave('bild', $imgurl);

uploads the picture and adds it to the existing one. So there are now a growing number of pictures in my "single item" field.

What i expected to happen was, that the new image would overwrite the existing one.

Am i doing something wrong or is there another setting that i missed?

(Sorry if i posted this in the wrong forum.)

Share this post


Link to post
Share on other sites

When you add an image via the API rather than via the inputfield you have to do all the work yourself that the inputfield would otherwise do for you. A recent answer to a similar question, which contains a link to some code that might be useful to you:

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you, i didn't know that.

I solved my problem by deleting all existing images in the field with

$imgfield->remove($image);

before saving the new one with setAndSave()

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...