Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

permission denied - php unlink

I have two files: b.php and test.txt

<?php  $b = "test.txt"; unlink($b); ?> 

and the error is: Warning: unlink(test.txt) [function.unlink]: Permission denied

why? b.php and test.txt is 777 and the same group/login

if I set 777 on the parent directory I can execute unlink but i have to set 777 and back to 755?

like image 507
eugui Avatar asked Nov 27 '12 23:11

eugui


1 Answers

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.

like image 59
Arjan Avatar answered Sep 17 '22 09:09

Arjan