简体   繁体   中英

How to delete all files and folder in php with permission?

I try to delete everything in folder (including subfolders) but:

Warning: unlink(./../kaj-content/theme/one-four): Permission denied in C:\\wamp\\www\\kaj\\kaj-admin\\includes\\incAppearance.php on line 36

this is my code:

$themeDirectory = './../kaj-content/theme';
$dir = $themeDirectory . '/' . $themeName;
array_map('unlink', glob($dir));

how can I change my code ?

Other code didn't work, like:

function rrmdir($dir) {
        if (is_dir($dir)) {
            $files = scandir($dir);
            foreach ($files as $file)
                if ($file != "." && $file != "..")
                    rrmdir("$dir/$file");
            rmdir($dir);
        } else if (file_exists($dir))
            unlink($dir);
    }

Your php code is running as a particular user, maybe apache. Your error means that php does not have the correct permissions for directory one-four.

Check the permissions on that directory. Grant write permission for that directory to the user that php is using. Then, your code will be able to delete the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM