Team
chmod("/home/www/tools/", 0777); changes the rights only to the tools folder, does not change them for nested ones.
If through the console, then the command
chmod -R 777 tools You can change the rights recursively.
And how to do this through the PHP function chmod, without looping through all the subfolders and files?