cabrooney Posted July 18, 2019 Share Posted July 18, 2019 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.) Link to comment Share on other sites More sharing options...
Robin S Posted July 21, 2019 Share Posted July 21, 2019 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: 1 Link to comment Share on other sites More sharing options...
cabrooney Posted July 22, 2019 Author Share Posted July 22, 2019 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() 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now