Lulzim
Lulzim

Reputation: 547

Permission denied when deleting file in PHP

This is driving me crazy already, cant delete a directory and its content using code:

    public function deleteDirectory($path) { 
     $files = glob($path . '/*');
     foreach ($files as $file) {
        is_dir($file) ? self::deleteDirectory($file) : unlink($file);
     }
     rmdir($path);
     return;
    } 

As I can see it is able to delete the folder, but when it comes to the file which i guess unlink($file) case, it doesnt allow me to delete bc of permission issue. I have no idea what can I do at the moment, any help would appreciate it alot.

Upvotes: 1

Views: 1194

Answers (1)

skbly7
skbly7

Reputation: 1162

It depends on the user who is executing the PHP Code you gave.
Are you running it as sudo or someone who has access to that directory & files ?

Possibly this PHP Code is being run by www-data, nginx, or some user like this, which don't have permission to that directory. Check the permission, and try again.

Upvotes: 2

Related Questions