function chmod_recursive($item, $mode) { // chmod file / dir $ok = true; if (@is_link($item) || @is_file($item)) { $ok = @chmod($item, $mode); if ($ok) { ext_Result::add_message($GLOBALS['messages']['permchange'] . ' ' . $new_item); } else { ext_Result::add_error($GLOBALS['error_msg']['permchange'] . ' ' . $new_item); } } elseif (@is_dir($item)) { if (($handle = @opendir($item)) === false) { ext_Result::add_error(basename($item) . ": " . $GLOBALS["error_msg"]["opendir"]); return false; } while (($file = readdir($handle)) !== false) { if ($file == ".." || $file == ".") { continue; } $new_item = $item . "/" . $file; if (!@file_exists($new_item)) { ext_Result::add_error(basename($item) . ": " . $GLOBALS["error_msg"]["readdir"]); continue; } //if(!get_show_item($item, $new_item)) continue; if (@is_dir($new_item)) { $ok = chmod_recursive($new_item, $mode); } else { $ok = @chmod($new_item, $mode); if ($ok) { ext_Result::add_message($GLOBALS['messages']['permchange'] . ' ' . $new_item); } else { ext_Result::add_error($GLOBALS['error_msg']['permchange'] . ' ' . $new_item); } } } closedir($handle); if (@is_dir($item)) { $bin = decbin($mode); // when we chmod a directory we must care for the permissions // to prevent that the directory becomes not readable (when the "execute bits" are removed) $bin = substr_replace($bin, '1', 2, 1); // set 1st x bit to 1 $bin = substr_replace($bin, '1', 5, 1); // set 2nd x bit to 1 $bin = substr_replace($bin, '1', 8, 1); // set 3rd x bit to 1 $mode = bindec($bin); } $ok = @chmod($item, $mode); if ($ok) { ext_Result::add_message($GLOBALS['messages']['permchange'] . ' ' . $item); } else { ext_Result::add_error($GLOBALS['error_msg']['permchange'] . ' ' . $item); } } return $ok; }