I have a script that creates a directory when an image is uploaded and places it there.

Right now I am writing a script that will delete some records and I need a script that will delete that image directory with the uploaded image. I came across a function in the manual php.net but it doesn't seem to be able to remove the directory. Directory CHMOD 755, but when I try to delete it via FTP browser, I get permission denied message. I think it's something to do with the way the directory was created. I have to login as an administrator to mysever to remove it.

How can I modify the function to obvercome this issue?

Here's the function I've attempted to use:

function full_rmdir($dirname)
    {
    if ($dirHandle = opendir($dirname))
        {
        $old_cwd = getcwd();
        chdir($dirname);

    while ($file = readdir($dirHandle))
        {
        if ($file == '.' || $file == '..') continue;

        if (is_dir($file))
            {
            if (!rmdir_rf($file)) return false;
            }
        else
            {
            if (!unlink($file)) return false;
            }
        }

    closedir($dirHandle);
    chdir($old_cwd);
    if (!rmdir($dirname)) return false;

    return true;
    }
else
    {
    return false;
    }
}

    the only problem i see with your function is that i've never heard of any function called rmdir_rf(). Do you mean that to be a recursive call to full_rmdir()?

    the real problem is probably with the permissions on the directory you are trying to delete (or its parent directory). your webserver runs as some user. on my machine, it's usually user 'www-data' or 'apache'. any directories you are trying to delete should probably be readable, writable, and executable for your webserver. any directories you are creating files or directories in should also be readable, writable, and executable.

      I found this function and actually was able to make it work by providing absolute path to the dir?..

        Write a Reply...