• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can not remove folder

#1
Bug 
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"));
 
       
Reply

#2
The directory must be empty for rmdir() to work.
Simpler is always better
Reply

#3
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.
Reply

#4
It could also contain a hidden file which you would not see.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
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"));
 
               }
 
           
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.