Question about making sure an image is completely removed from your CRUD application - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Question about making sure an image is completely removed from your CRUD application (/showthread.php?tid=82484) |
Question about making sure an image is completely removed from your CRUD application - Son of Troy - 07-15-2022 Question about making sure a image is completely removed from the database and file path when using CRUD I'm currently building an application using CRUD. The app displays images. I followed a tutorial about their method on how to building a CRUD app with images. My current bug is when I delete the image, it is removed from the database however it's not removed from the uploads folder. Additional information, before submitting the form the image you select will be stored in the database and in the folder you create located the public directory. What else can I add to my program that would accomplish complete deletion from the database and file path. Thanks! I have snippets of my program posted here: My Controller: PHP Code: <?php My View: PHP Code: <?= $this->extend('App\Views\templates\default'); ?> My file path: Code: public: RE: Question about making sure an image is completely removed from your CRUD application - php_rocs - 07-15-2022 @Son of Troy, What version of CI are you using? RE: Question about making sure an image is completely removed from your CRUD application - kenjis - 07-15-2022 Your delete() method just delete the record in the database. You need to add the code to delete the file in the uploads folder. RE: Question about making sure an image is completely removed from your CRUD application - demyr - 07-15-2022 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 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. RE: Question about making sure an image is completely removed from your CRUD application - Son of Troy - 07-16-2022 (07-15-2022, 04:49 PM)php_rocs Wrote: @Son of Troy, What version of CI are you using? @php_rocs I'm currently using CodeIgniter V.4 RE: Question about making sure an image is completely removed from your CRUD application - Son of Troy - 07-16-2022 @demyr Thank you for your help. I used your solution and made small changes. and now it's working. I'll post the solution below. The delete method used to remove data from the men's / boy's wrestling roster. The data is removed from both the database and filesystem. PHP Code: /** |