/** * Delete the product image from disk and remove the containing folder if empty * Handles both legacy and new image filesystems */ public function deleteImage($force_delete = false) { if (!$this->id) { return false; } // Delete base image if (file_exists($this->image_dir . $this->getExistingImgPath() . '.' . $this->image_format)) { unlink($this->image_dir . $this->getExistingImgPath() . '.' . $this->image_format); } else { return false; } $files_to_delete = array(); // Delete auto-generated images $image_types = BlogImageType::getImagesTypes(); foreach ($image_types as $image_type) { $files_to_delete[] = $this->image_dir . $this->getExistingImgPath() . '-' . $image_type['name'] . '.' . $this->image_format; } // Delete watermark image $files_to_delete[] = $this->image_dir . $this->getExistingImgPath() . '-watermark.' . $this->image_format; // delete index.php $files_to_delete[] = $this->image_dir . $this->getImgFolder() . 'index.php'; // Delete tmp images $files_to_delete[] = _PS_TMP_IMG_DIR_ . 'product_' . $this->id_smart_blog_post . '.' . $this->image_format; $files_to_delete[] = _PS_TMP_IMG_DIR_ . 'product_mini_' . $this->id_smart_blog_post . '.' . $this->image_format; foreach ($files_to_delete as $file) { if (file_exists($file) && !@unlink($file)) { return false; } } // Can we delete the image folder? if (is_dir($this->image_dir . $this->getImgFolder())) { $delete_folder = true; foreach (scandir($this->image_dir . $this->getImgFolder()) as $file) { if ($file != '.' && $file != '..') { $delete_folder = false; break; } } } if (isset($delete_folder) && $delete_folder) { @rmdir($this->image_dir . $this->getImgFolder()); } return true; }