Files that need to be written to by PHP need to be 666 and folders 777. Files should never really be 777. And you should be able to simply make them 775 and 664 if the owner is nobody or whatever the user account is that is executing Apache.
If you have SSH access to your account, you can do something like this to make all directories or files below the current directory have these proper ownership/permissions:
chown -R myaccount.apacheuser .
find . -type d -exec chmod 0775 {} \;
find . -type f -exec chmod 0664 {} \;
This changes group ownership to the apacheuser (will be called "nobody" on many servers) and then provides write access to folders and files to this user while not providing world-writable permissions which could theoretically allow any user on the machine to modify the contents.
However, you only want to do this to the files/folders that need to be writable since it does give PHP the ability to write to those files from any other account. This is why most hosts are switching to suExec to better limit access to your account from malicious users on the same machine.