permission denied - php unlink
in addition to all the answers that other friends have , if somebody who is looking this post is looking for a way to delete a "Folder" not a "file" , should take care that Folders must delete by php rmdir() function and if u want to delete a "Folder" by unlink()
, u will encounter with a wrong Warning message that says "permission denied"
however u can make folders & files by mkdir()
but the way u delete folders (rmdir()
) is different from the way you delete files(unlink()
)
eventually as a fact:
in many programming languages, any permission related error may not directly means an actual permission issue
for example, if you want to readSync
a file that doesn't exist with node fs module
you will encounter a wrong EPERM
error
You'll first require to close the file using fclose($handle);
it's not deleting because the file is in use. So first close the file and then try.
You (as in the process that runs b.php
, either you through CLI
or a webserver) need write access to the directory in which the files are located. You are updating the directory content, so access to the file is not enough.
Note that if you use the PHP chmod()
function to set the mode of a file or folder to 777
you should use 0777
to make sure the number is correctly interpreted as an octal number.