(am a little curious as to why it will upload to dir upload with 755 permissions but not move to photos dir unless permissions are 777)
Depends on who the owner of the folder(s) are. Try and follow this:
"r" = Read rights, "w" = Write rights, "x" = Execute rights
1.) 777 is owner: rwx, group: rwx, global: rwx
2.) 755 is owner: rwx, group: r-x, global: r-x
So if Apache was the owner of the temp directory, it only needs to be 755. If you're the owner of the photos directory, and you're NOT using FTP functions to move files there (i.e. you're using PHP (which is Apache's user ID) to move the files) then you need to allow others to write to it (777 permissions).
I hope that makes some type of sense to you.
foreach($_FILES['userfile'] returns "Invalid argument supplied for foreach()"
Well, that confirms exactly what I thought: your upload is working. So somewhere between the form and PHP processing, something is going wrong.
So in that case, try this:
<?php
// Get the type of the variable:
echo gettype($_FILES['userfile']);
// If it's a string, let's try and set it back to an array, see what happens:
if(gettype($_FILES['userfile']) == "string")
settype($_FILES['userfile'], "array");
// Now let's see some results of our type-casting...
print_r($_FILES['userfile']);
[EDIT]
For the permissions thing, think of it this way:
Right | Value
Read | 4
Write | 2
Execute | 1
So, if you add them together (for rwx permissions) you get 7 😉 Now, the Owner is $perm100, and the group is $perm10, and the global community is $perm. So:
Owner: r-x || 4+1 = 5 100 = 500
Group: r-- || 4 = 4 10 = 40
Global: r-- || 4 = 4 = 4
Permission Value: 500+40+1 = 541
Owner: rwx || 4+2+1 = 7 100 = 700
Group: -wx || 2+1 = 3 10 = 30
Global: r-x || 4 + 1 = 5 = 5
Permission Value: 700+30+5 = 735
Hopefully now you can see how they arrive at the octal values they do, and hopefully that will help you understand a little bit more. You can read more here. It's pretty in-depth, but goes over nothing I haven't already told you. Although it most likely is written better than I wrote above.
[EDIT]
Reversed my numbers... 😊 Thanks Clark for pointing it out.