CodeIgniter Forums

Full Version: I can not remove folder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to delete a record from database and remove its own folder. You can see the code below. I wrote "problem occurred- ALWAYS WORK THIS IF". I can not solve this problem. I'm waiting for your help  Angel

PHP Code:
 public function delete($incomingId)
 
   {
 
       $gallery $this->gallery_model->get(
 
           array(
 
               'id' => $incomingId
            
)
 
       );
 
       if ($gallery) {

 
           if ($gallery->gallery_type != 'video') {
 
               if ($gallery->galery_type 'image') {
 
                   $path "uploads/$this->viewFolder/images/$gallery->folder_name";
 
               } elseif ($gallery->galery_type 'files') {
 
                   $path "uploads/$this->viewFolder/files/$gallery->folder_name";
 
               }
 
               $delete_folder rmdir($path);
 
               if (!$delete_folder) { // always this works begin
 
                   $alert = array(
 
                       "title" => "Error",
 
                       "text" => "problem occurred- ALWAYS WORK THIS IF",
 
                       "type" => "error"
 
                   );
 
               // always this works end
 
               // session
 
               $this->session->set_flashdata("alert"$alert);
 
               redirect(base_url("galleries"));
 
               die;
 
           }
 
           $delete $this->gallery_model->delete(
 
               array(
 
                   'id' => $incomingId
                
));
 
           if ($delete) {
 
               $alert = array(
 
                   "title" => "Success",
 
                   "text" => "OK.",
 
                   "type" => "success"
 
               );

 
           } else {

 
               $alert = array(
 
                   "title" => "Error",
 
                   "text" => "problem occurred",
 
                   "type" => "error"
 
               );
 
           }
 
           $this->session->set_flashdata("alert"$alert);
 
           redirect(base_url("galleries"));
 
       
The directory must be empty for rmdir() to work.
Most likely either the directory is not empty or your script doesn't have permission to delete it. If it's not empty, you could try the file_helper and its delete_files method, which will delete all files within the directory and can optionally delete the directory itself.
It could also contain a hidden file which you would not see.
Okay it's my fault. I changed this

Old code (not work)
PHP Code:
$delete_folder rmdir($path);  
if (!$delete_folder) { // always this works begin
 
                   $alert = array(
 
                       "title" => "Error",
 
                       "text" => "problem occurred- ALWAYS WORK THIS IF",
 
                       "type" => "error"
 
                   );
 
               // always this works end
 
               // session
 
               $this->session->set_flashdata("alert"$alert);
 
               redirect(base_url("galleries"));
 
               die
New code (it works)
PHP Code:
    $delete_folder delete_files($path);
 
               if (!$delete_folder) {
 
                   $alert = array(
 
                       "title" => "Error",
 
                       "text" => "problem occurred-.",
 
                       "type" => "error"
 
                   );
 
                   $this->session->set_flashdata("alert"$alert);
 
                   redirect(base_url("galleries"));
 
               }