简体   繁体   中英

Files won't delete

I ran chown -R www-data:www-data /srv/www/dev.example.com/public_html/uploads/ didn't work Tried chmod 777 didn't work.

define('UPLOADPATH', "/srv/www/dev.example.com/public_html/uploads/members/");
$userId = 6;
$dir = UPLOADPATH . $userId;
rmdir($dir);

isn't removing the users folder(This runs to wipe out all their files, when deleting account). also(To delete just one photo)

 $RemovePreview = UPLOADPATH . $userId. '/' . $file . '_preview.' . $image_ending;
                        if (file_exists($RemovePreview))
                        {
                            @unlink($RemovePreview);
                        }

file and image_ending are coming from my Database. Also won't delete the file.

I really don't know whats up. Not sure if this is a Php, Server or both issue?

Is your directory empty? The Documentation to rmdir says that the directory needs to be empty; what you might be looking for is a recursive version of rmdir:

function rrmdir($dir)
{
    if (is_dir($dir)) {
        $objects = scandir($dir);
        foreach ($objects as $object) {
            if ($object != "." && $object != "..") {
                if (filetype($dir."/".$object) == "dir")
                    rrmdir($dir."/".$object);
                else
                    unlink($dir."/".$object);
            }
        }
        reset($objects);
        rmdir($dir);
    }
} 

在您不拥有的文件或目录上尝试chown或chmod时,请使用sudo。

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