Note: this section applies only to those using PHP on a Unix-like operating system. The reason for this is because Windows has a vastly different security system to Unix, where privileges are handed out by user and user group.
If you are using a Unix box, you can use PHP's chmod() function like you would use chmod from the command line, with the difference that you need to precede the security level with a 0 to show that it is an octal value. Chmod() takes two parameters: the file to set, and the value to set it to. Here are two examples:
Line one sets the file to readable, writeable, and executable by all users, whereas line two sets the file to readable, writeable, and executable by owner, and just readable and writeable by everyone else.