joer80 Posted January 21, 2015 Posted January 21, 2015 I have code that adds a remote image to a page that works great, but I want it to run and copy over the old image instead of adding it again and having both on the page. Is there a way to tell it to replace the old one? This is what I have so far: I first pass a | delimited string saved as $imageArray into this: $m->setOutputFormatting(false); foreach($imageArray as $image){ if($image){ echo "Saving " . $image . " to " . $m->id . "<br>"; $m->images->add($image); } } $m->save(); Thanks!
kongondo Posted January 21, 2015 Posted January 21, 2015 (edited) Check your image's fields Input Tab and tick checkbox at 'Overwrite existing files?' Since version 2.5.1 Edited January 21, 2015 by kongondo 3
LostKobrakai Posted January 21, 2015 Posted January 21, 2015 Dev version of PW only (since 2.5.1) 2.5.3 is the stable version, so this should be included even there. 2
kongondo Posted January 21, 2015 Posted January 21, 2015 You are right, of course...I am having one of those days...I better go to bed
Xonox Posted September 12, 2018 Posted September 12, 2018 Hi, I tried to use the same technique and it's not working. I checked the image field to overwrite but the API keeps adding files, with "-1", "-2", "-3" appended to the filename. Here's my code: foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Upload image into book $book->book_images->add($upload_directory . '/' . $file); // Delete file unlink($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); } } I don't know what's missing.
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