Answer the question
In order to leave comments, you need to log in
Deleting a product, how can I make sure that when deleting a product, the photo of the product is deleted?
Hello , how to implement the complete deletion of the product, at the moment after the product the photo remains on the server, how to make sure that when deleting the product, all the photos that are in the product are deleted, deleted from the hosting.
Site on Kohana 3.1
Action for deleting a product:
public function action_delete()
{
$id = (int)$this->request->param('id');
$products = ORM::factory('product', $id);
$products->delete();
$this->request->redirect('admin/products');
}
public function action_delimg()
{
$id = (int)$this->request->param('id');
$images = ORM::factory('image', $id);
$product_id = $images->product_id;
if (!$images->loaded()) {
$this->request->redirect('admin/products');
}
$p_db = ORM::factory('product', $product_id);
if ($p_db->image_id == $id) {
$p_db->image_id = 0;
$p_db->save();
}
@unlink('media/uploads/' . $images->image);
@unlink('media/uploads/small/small_' . $images->image);
$images->delete();
$this->request->redirect('admin/products/edit/' . $product_id);
}
Answer the question
In order to leave comments, you need to log in
get an array of photos and delete them
Can the photo be used in another product?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question