Search code examples
phppermissionschmodunlink

Can't do unlink or chmod - permissions denied


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 ?


Solution

  • 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.