I have a PHP script that deletes files. It can delete files from my root directory, but when I try to delete from a subdirectory, it says “Permission denied”. I know the file exists and PHP can access it because I can read and write to the file, but I can’t delete it.
Why?
EDIT: If this is relevant, I am using Zymic hosting. But I have another site on Zymic where the deleting works fine. I don’t get it…
EDIT: I use ajax to access the PHP file with the code to delete, and the ajax sends the file name to delete. I know the file name it sends is correct, because the warning message prints it for me. The PHP code is simply:
$file=$_POST['file'];
echo unlink($file);
EDIT: I fixed it! I don’t know why this worked, but I FTP-chmodded the directory from 755 to 775 Can anyone tell me why it worked?
To delete the file you need write permissions to the folder that contains it, check that first.
CHMOD xxx -> Owner Group Other
first case:
755 – Owner (read, write, execute), Group (read, execute), Other (read, execute)
second case:
775 – Owner (read, write, execute), Group (read, write, execute), Other (read, execute)