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

Saturday, January 1, 2022

[FIXED] Delete file from folder in CodeIgniter

 January 01, 2022     codeigniter     No comments   

Issue

I am trying to delete a file whose name is saved in $category_image. But the function delete_files() is not deleting.

public function deleteCategory($id,$category_image)
{
    $this->load->helper('file');
    //echo FCPATH.'/uploads/'.$category_image;

     delete_files(FCPATH.'/uploads/'.$category_image,false,false);die;
    //$this->load->model('AdminModel')->deleteCategory($id);
}

Solution

The problem is that delete_files() is the wrong function to use. It is designed to "Deletes all files contained in the supplied directory path." - not to delete a single file. The addition of a file name at the end of the path causes the function to fail.

Just use unlink()

unlink(FCPATH.'uploads/'.$category_image);die;

Note that the constant FCPATH already has a directory separator at the end so don't add another before 'uploads/'.



Answered By - DFriend
  • 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