Jump to content

Recommended Posts

Posted

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.)

Posted

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
Posted

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

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
  • Recently Browsing   0 members

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