Q:

Uploading files with PHP on a linux machine

I'm trying to make some sort of cloud application on a headless raspbian machine. 
The testing happens on a wamp-server running on windows8.1.  PHP version is 5.6
The code works fine on my testing windows, but I run into issues when running the same code on my linux server.  I've narrowed down the issue to the fact that (the linux user behind) my PHP code doesn't have write permissions on the folder where it should store files. 
I can think of two ways to solve the issue: either give that php-user permissions, or change the user behind the php code.  The last one would be quite interesting if it was possible to change per-script. 
So, for my concrete question:
1) Where can I find what user is being used by my PHP code?   
2) Can I change what user my PHP code uses, preferably on a per-project basis? 
EDIT:
My script was running as root, as is shown by echo get_current_user();.  I changed ownership of all files to root:webhosting, which was previously ftpuser:ftpgroup.  However, when setting permissions to 770 I get access denied
EDIT2:
When using var_dump(posix_geteuid()); instead of get_current_user();, i get UID 33, which matches user www-data. 
SOLUTION:
By looking at the EUID with var_dump(posix_geteuid(); I was able to validate the actual user, which does NOT match the get_current_user();.  Changing the directroy and all files in it with sudo chown -R www-data:www-data <root of site> I managed to set the correct permissions. 

A:

I am not sure what the specifics are but normally when I have issues like that I change the ownership to www-data:www-data and if necessary for upload folders I change the folder permissions to 0755 and inside files permissions to 0644. 
EDIT
I changed the permissions setting for security purposes.