The file has to be owned by the user that the webserver runs as, or have higher permissions to begin with.
If any user could chmod any files then hosts would never be able to secure their systems. Any user could use php to chmod 777 /etc/passwd and view a list of the users.
You need to chown -R nobody.nobody <path> in order to change the owner. And then chmod is not even needed.
If you can convince the admin of your server to turn safe_mode off, that may relieve some stress, but as it implies, its no longer in safe_mode then. ( Might want to research this, I heard this, but not 100% sure. )