You may not be able to change the user ownership of every new file created in a particular folder to www-data. But you can change the group ownership of every new file created in a particular folder to www-data by setting the setgid flag of the directory.
nifty:~# whoami
root
nifty:~# mkdir foo
nifty:~# chown www-data:www-data foo
nifty:~# chmod g+s foo
nifty:~# ls -l
total 4
drwxr-sr-x 2 www-data www-data 4096 Nov 17 21:49 foo
nifty:~# touch foo/hi.txt
nifty:~# ls -l foo
total 0
-rw-r--r-- 1 root www-data 0 Nov 17 21:52 hi.txt
Note that you cannot change the user ownership of the new files created in a particular folder automatically because setting the setuid flag on a directory has no effect.
nifty:~# mkdir bar
nifty:~# chown www-data:www-data bar
nifty:~# chmod a+s bar
nifty:~# ls -l
total 8
drwsr-sr-x 2 www-data www-data 4096 Nov 17 21:54 bar
drwxr-sr-x 2 www-data www-data 4096 Nov 17 21:52 foo
nifty:~# touch bar/hi.txt
nifty:~# ls -l bar
total 0
-rw-r--r-- 1 root www-data 0 Nov 17 21:54 hi.txt
Thanks! I was wondering if it's also possible to chmod the newly added files to 766 automatically. – Niek – 2013-11-17T16:48:22.703
It's not possible to change the permissions of newly added files within a particular directory only without using ACLs. However, you can temporarily change umask in your shell or the program or script creating files to set the permissions of new files created anywhere on the file system to 666 automatically with the command:
umask +rwx
. – Susam Pal – 2013-11-17T17:14:09.937Thank you! I ended up using ACLs. This answer is very informative
– Niek – 2013-11-17T18:05:33.467