The following should help
realpath
— Returns canonicalized absolute pathnameis_writable
— Tells whether the filename is writableunlink
— Deletes a file
Run your filepath through realpath, then check if the returned path is writable and if so, unlink it.