PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] How to delete uploaded image from directory folder in CodeIgniter

 March 05, 2022     codeigniter, image, php     No comments   

Issue

I want to delete the image not only in database, but in folder too.

This is my database table:

group_id
group_name
group_descrtion
group_picture

This is my controller :

    public function delete_group()
    {
            $group_id = $this->input->post('group_id');
            $group_picture = $this->input->post('group_picture');

            $this->group_model->delete_group($group_id, $group_picture);
            redirect('product_group');
    }

this is my model :

        function delete_group($group_id, $group_picture)
        {
                $this->db->where('group_id', $group_id);

                unlink(base_url("uploads/".$group_picture));

                $this->db->delete('product_group', array('group_id' => $group_id));
        }

and this is my view :

 <?=form_open_multipart('product_group/delete_group');?>

   <input type="hidden" class="form-control" placeholder="Group ID" name="group_id">
   <input type="text" class="form-control" placeholder="Group ID" name="group_picture">

  <div class="modal-footer">
     <button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
     <button class="btn btn-success" type="submit">Submit</button>
   </div>
 </form>

I succeed in deleting the data in the database, but the image in the folder are not also be deleted.


Solution

unlink(base_url("uploads/".$group_picture));

Should be

unlink("uploads/".$group_picture);

You need the path, not the url.



Answered By - Jeremy Jackson
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing