Welcome Guest, Not a member yet? Register   Sign In
Question about making sure an image is completely removed from your CRUD application
#4

(This post was last modified: 07-15-2022, 10:45 PM by demyr.)

It is not so difficult to delete from the folder as well. You need "unlink" function in PHP and you can find regular php tutorials on internet for this. Let me write you the basic idea:

Here is an example of Controller part. In your view, I assume you have a form tag containing the inputs I write down here

   
PHP Code:
$product_id $this->request->getVar('product_id'); // Probably you will keep it as a hidden input in your form
$product_image_link $this->request->getVar('product_image_link'); //the name part of the image link. Keep it as a hidden input in your form so that you can use it here.
$product_image_id $this->request->getVar('product_image_id'); // you will need this to delete from the database

    $folder 'uploads/products/product-'.$product_id.'/images';
        if(file_exists($folder.'/'.$product_image_link)) {
            unlink($folder.'/'.$product_image_link);
           $this->YourProductModel->delete($product_image_id); //deleting from the database
        

Good luck

P.S. If you cannot display directly the name of the image for $product_image_link , you can display the complete url that you keep in your database and use explode() function here in order to get the name part of it.
Reply


Messages In This Thread
RE: Question about making sure an image is completely removed from your CRUD application - by demyr - 07-15-2022, 10:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB