Is it possible to run a script withing a directory containing other directories and if the subdirectory mode is 0755, chmod it to 0777?
Yes.... so long as the user that PHP is running as has permission to change permissions on that file/folder...