Hello,
Did you specify the mode like this?
You need a prefix zero before '311'.
Also, regarding the chown(), you need to specify either user name or its uid, which means this user has to exist on your server. In addition, it has to be a superuser in order to use chown() to change the file owner to whom other than 'nobody' or 'Apache' or whatever the default is or you'll get an error message like "operation not permitted".
Hope this helps.