Hi,
I'm trying to upload images from a folder into a page. I need to replace the images instead of adding. The image field already has the replace existing images turned on, but it doesn't seem to be enough.
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 !!! THIS CODE ADDS FILE INSTEAD OF REPLACING. HOW CAN I REPLACE?
$book->book_images->add($upload_directory . '/' . $file);
// Delete file
unlink($upload_directory . '/' . $file);
}
// Save book
if($book->id) $book->save();
}
}
What am I missing?