[man]is_writable[/man] is a good way to determine if you can write to a file, since 666 can sometimes be a bad thing on some servers (ones with suExec).
or you can use [man]fileperms[/man] to get the integer value of a file permissions and then convert it to octal to check for what you want.