+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP - unlink() returning true, but not deleting file

  1. #1
    kbjradmin's Avatar
    kbjradmin is offline x10 Elder kbjradmin is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    Washington State, USA
    Posts
    512

    PHP - unlink() returning true, but not deleting file

    I am using the following PHP function to recursively delete directories:
    PHP Code:
    class Classname{
    //...

    public function rmdir($dir) {
        if (
    is_dir($dir)) {
            
    $objects scandir($dir);
            foreach (
    $objects as $object) {
                if (
    $object != "." && $object != "..") {
                    
    chmod("$dir/$object"0777);
                    if (
    filetype("$dir/$object") == "dir")
                        
    $this->rmdir("$dir/$object");
                    else 
    unlink("$dir/$object");
                }
            }
            
    reset($objects);
            
    rmdir($dir);
        } 
    }

    //...

    The unlink() call is returning false (i tested it by wrapping it in a var_dump() call), but the file is not being deleted. I really have no idea what is wrong here. Help?

  2. #2
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep Brandon is on a distinguished road
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,589

    Re: PHP - unlink() returning true, but not deleting file

    Are the files chowed to your account?
    Thanks,
    Brandon Long

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP - unlink() returning true, but not deleting file

    Is unlink returning true or false? The thread title says one thing, your post another. If it's returning false, use set_error_handler to capture the error or error_reporting (temporarily) to output it. The former is what you should do in production code, the latter for quick & dirty debugging.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Trouble Deleting File From Public_HTML
    By toxictwister in forum Free Hosting
    Replies: 3
    Last Post: 05-09-2010, 05:51 PM
  2. Unlink
    By Fsmv413 in forum Free Hosting
    Replies: 1
    Last Post: 10-11-2008, 06:29 PM
  3. php unlink directory help
    By nahsorhseda in forum Programming Help
    Replies: 6
    Last Post: 01-02-2008, 02:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers