$ext_to = fn_get_file_ext($pname_to); if (in_array(fn_strtolower($ext_from), Registry::get('config.forbidden_file_extensions')) || in_array(fn_strtolower($ext_to), Registry::get('config.forbidden_file_extensions'))) { fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext_to))); } elseif (fn_te_check_path($pname) && fn_rename($pname, $pname_to)) { fn_set_notification('N', __('notice'), __("text_{$object}_renamed", array("[{$object}]" => fn_basename($pname), "[to_{$object}]" => fn_basename($pname_to)))); } else { fn_set_notification('E', __('error'), __("text_cannot_rename_{$object}", array("[{$object}]" => fn_basename($pname), "[to_{$object}]" => fn_basename($pname_to)))); } return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']); } elseif ($mode == 'create_file') { $file_path = fn_te_normalize_path($_REQUEST, $root_dir); $file_info = fn_pathinfo($file_path); if (in_array(fn_strtolower($file_info['extension']), Registry::get('config.forbidden_file_extensions')) || empty($file_info['filename'])) { fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $file_info['extension']))); } elseif (fn_te_check_path($file_path) && @touch($file_path)) { fn_te_chmod($file_path, DEFAULT_FILE_PERMISSIONS, false); fn_set_notification('N', __('notice'), __('text_file_created', array('[file]' => fn_basename($file_path)))); } else { fn_set_notification('E', __('error'), __('text_cannot_create_file', array('[file]' => fn_basename($file_path)))); } return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']); } elseif ($mode == 'create_folder') { $folder_path = fn_te_normalize_path($_REQUEST, $root_dir); if (fn_te_check_path($folder_path) && fn_mkdir($folder_path)) { fn_set_notification('N', __('notice'), __('text_directory_created', array('[directory]' => fn_basename($folder_path)))); } else { fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_basename($folder_path)))); } return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']); } elseif ($mode == 'get_file') { $pname = fn_te_normalize_path($_REQUEST, $root_dir);
function fn_te_chmod($source, $perms = DEFAULT_DIR_PERMISSIONS, $recursive = false) { // Simple copy for a file if (is_file($source) || $recursive == false) { $res = @chmod($source, $perms); return $res; } // Loop through the folder if (is_dir($source)) { $dir = dir($source); while (false !== ($entry = $dir->read())) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } if (fn_te_chmod($source . '/' . $entry, $perms, true) == false) { return false; } } // Clean up $dir->close(); return @chmod($source, $perms); } else { return false; } }