I'm trying to chmod a file to 777 permissions and then delete it using unlink in PHP. However, I'm getting permissions denied error. I'm able to change the permissions when logged in via FTP in filezilla though.
How do I fix this ?
I'm trying to chmod a file to 777 permissions and then delete it using unlink in PHP. However, I'm getting permissions denied error. I'm able to change the permissions when logged in via FTP in filezilla though.
How do I fix this ?
You're probably getting permission denied because PHP may be running with special permissions, which means that you will not be able to change the permissions of that file from PHP, however, you are going to be able to delete it by using an FTP manager. If you still want to be able to change the permissions of that file, you may need to create a special user to run PHP or if you're using a host, you may need to contact the host that is providing you the web service. I'll just let you know that giving more permissions to PHP could open up to security risks over time.
I would suggest you to try following.
while(is_file($data_file_to_delete) == TRUE)
{
chmod($data_file_to_delete, 0666);
unlink($data_file_to_delete);
}
If it does not work then try this
unlink('ftp://user:pass@host/absolute/path/to/file');
If none of these work, then I would think of using more complicated FTP functions.