Removing directory using codeigniter

后端 未结 4 985
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 15:47

I\'m new to codeigniter so please forgive me, I am trying to make codeigniter delete a base folder (I don\'t know what the right term is, it\'s the folder where I put my up

相关标签:
4条回答
  • 2020-12-20 15:51

    You can do it using "delete_files" function:

    $path = "the path that has files those will be deleted";
    $this->load->helper("file"); // load codeigniter file helper
    delete_files($path, true , false, 1); //  second and the last parameters are required, second parameter should be true and the last parameter should be greater than 0
    
    0 讨论(0)
  • 2020-12-20 15:51
    // Delete Directory
    public function delete_directory($folderName)
    {
          $this->load->helper('file'); // Load codeigniter file helper
    
          $dir_path  = 'uploads/'.$folderName;  // For check folder exists
          $del_path  = './uploads/'.$folderName.'/'; // For Delete folder
    
          if(is_dir($dir_path))
          {
               delete_files($del_path, true); // Delete files into the folder
               rmdir($del_path); // Delete the folder
    
               return true;
          }
          return false;
     }
    
    0 讨论(0)
  • 2020-12-20 15:56
    $this->load->helper("file"); // load codeigniter file helper
    delete_files('./path/to/directory/', TRUE); // Delete all files/folders in the dir
    

    If you want to delete the empty folder(dir), add below line after above two lines

    rmdir('./path/to/directory');
    
    0 讨论(0)
  • 2020-12-20 16:06

    You can delete all files using delete_files function

    $path=$this->config->base_url().'dir_name';
    $this->load->helper("file"); // load the helper
    delete_files($path, true); // delete all files/folders
    

    Above code will delete all files and folders from the given path and if once the directory is empty then you can use rmdir which deletes an empty directory, like

    rmdir($path);
    

    The folder should permit relevant permissions, which means files/folder must be writable or owned by the system in order to be deleted.

    0 讨论(0)
提交回复
热议问题