Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: (solved) delete dir and content

  1. #11
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    In post 4 you've only set up the function. You never actually call it. To call a function you put its name and the value(s) you're passing it in parenthesis. So add this

    PHP Code:
    DELETE_RECURSIVE_DIRS($path); 
    to post 4.
    Corrections to my coding/thoughts welcome.

  2. #12
    Join Date
    Feb 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i get the below errors and it has deleted pictures out of first folder
    Warning: unlink(../../gallery2.0/gallery_files/gallery/folder/thumbnails) [function.unlink]: Is a directory in /hermes/bosweb/web230/b2302/ipg.removed/test_server/admin/gallery/index.php on line 60

    Warning: rmdir(../../gallery2.0/gallery_files/gallery/folder/thumbnails) [function.rmdir]: Directory not empty in /hermes/bosweb/web230/b2302/ipg.removed/test_server/admin/gallery/index.php on line 61

    Warning: rmdir(../../gallery2.0/gallery_files/gallery/folder/pic.jpg) [function.rmdir]: No such file or directory in /hermes/bosweb/web230/b2302/ipg.removed/test_server/admin/gallery/index.php on line 61

    Warning: rmdir(../../gallery2.0/gallery_files/gallery/folder) [function.rmdir]: Directory not empty in /hermes/bosweb/web230/b2302/ipg.removed/test_server/admin/gallery/index.php on line 65
    this is the script
    Code:
    <?php
    $path = "../../gallery2.0/gallery_files/gallery/";
    if(isset($_POST['file']) && is_array($_POST['file']))
    {
    	foreach($_POST['file'] as $file)
    	{	
    		
    $dirname = $path.$file; 
    
    //Recursive Delete Function
    
    function DELETE_RECURSIVE_DIRS($path) //line 60
    { // recursive function to delete                line 61
      // all subdirectories and contents: 
      if(is_dir($dirname))$dir_handle=opendir($dirname); 
      while($file=readdir($dir_handle)) 
      {                                                      //line 65
        if($file!="." && $file!="..") 
        { 
          if(!is_dir($dirname."/".$file))unlink ($dirname."/".$file); 
          else DELETE_RECURSIVE_DIRS($dirname."/".$file); 
        } 
      } 
      closedir($dir_handle); 
      rmdir($dirname); 
      return true; 
    }
    
    	}
    }
    ?>

  3. #13
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That's still the same thing. You still are only declaring/setting up the function.

    Try this

    example 1
    PHP Code:
    $value "I'm a value"
    example 2

    PHP Code:
    $value "I'm a value";
    echo 
    $value//DELETE_RECURSIVE_DIRS($path); <--replace with this in your other code, this is only as an example. echo, and others are php functions 
    Corrections to my coding/thoughts welcome.

  4. #14
    Join Date
    Feb 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i have got this working and it is called from a separate script

    thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •