public function action($parent) { $s = new SessionHandler($parent->app); $s->setClipboardPath(null); $s->setClipboardPathThumb(null); $this->r = array("", 200); }
public function action($parent) { $s = new SessionHandler($parent->app); $util = new Utility(); $c = $parent->config; if ($_POST['sub_action'] != 'copy' && $_POST['sub_action'] != 'cut') { $this->error('wrong sub-action'); return; } if (trim($_POST['path']) == '' || trim($_POST['path_thumb']) == '') { $this->error('no path'); return; } $path = $c['current_path'] . $_POST['path']; if (is_dir($path)) { // can't copy/cut dirs if ($c['copy_cut_dirs'] === false) { $this->error(sprintf('You are not allowed to %s $s.', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', 'folders')); return; } // size over limit if ($c['copy_cut_max_size'] !== false && is_int($c['copy_cut_max_size'])) { if ($copy_cut_max_size * 1024 * 1024 < $util->foldersize($path)) { $this->error(sprintf('The selected files/folders are too big to %s. Limit: %d MB/operation', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', $c['copy_cut_max_size'])); return; } } // file count over limit if ($copy_cut_max_count !== false && is_int($copy_cut_max_count)) { if ($copy_cut_max_count < filescount($path)) { $this->error(sprintf('You selected too many files/folders to %s. Limit: %d files/operation', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', $c['copy_cut_max_count'])); return; } } } else { // can't copy/cut files if ($c['copy_cut_files'] === false) { $this->error(sprintf('You are not allowed to %s files.', $_POST['sub_action'] == 'copy' ? 'copy' : 'cut', 'files')); exit; } } $s->setClipboardPath($_POST['path']); $s->setClipboardPathThumb($_POST['path_thumb']); $s->setClipboardAction($_POST['sub_action']); }
public function action($parent) { $util = new Utility(); $app = $parent->app; $session = new SessionHandler($app); $path = $parent->path; $path_thumb = $parent->path_thumb; $c = $parent->config; $action = $session->getClipboardAction(); $data = array("path" => $session->getClipboardPath(), "path_thumb" => $session->getClipboardPathThumb()); if (!isset($action, $data['path'], $data['path_thumb']) || $action == '' || $data['path'] == '' || $data['path_thumb'] == '') { $this->r = array('no clipboard data found.', 200); return; } $data['path'] = $c['current_path'] . $data['path']; $pinfo = pathinfo($data['path']); // user wants to paste to the same dir. nothing to do here... if ($pinfo['dirname'] == rtrim($path, '/')) { $this->r = array('', 200); return; } // user wants to paste folder to it's own sub folder.. baaaah. if (is_dir($data['path']) && strpos($path, $data['path']) !== FALSE) { $this->r = array('', 200); return; } // something terribly gone wrong if ($action != 'copy' && $action != 'cut') { $this->r = array('no action', 400); return; } // check for writability if ($util->is_really_writable($path) === FALSE || $util->is_really_writable($path_thumb) === FALSE) { $this->r = array('The directory you selected is not writable <br/>' . str_replace('../', '', $path) . '<br/>' . str_replace('../', '', $path_thumb), 403); return; } // check if server disables copy or rename if ($util->is_function_callable($action == 'copy' ? 'copy' : 'rename') === FALSE) { $response = sprintf('The %s function has been disabled by the server.', $action == 'copy' ? 'copy' : 'cut'); $this->r = array($response, 403); return; } if ($action == 'copy') { $util->rcopy($data['path'], $path); $util->rcopy($data['path_thumb'], $path_thumb); } elseif ($action == 'cut') { $util->rrename($data['path'], $path); $util->rrename($data['path_thumb'], $path_thumb); // cleanup if (is_dir($data['path']) === TRUE) { $util->rrename_after_cleaner($data['path']); $util->rrename_after_cleaner($data['path_thumb']); } } // cleanup $session->setClipboardAction(NULL); $session->setClipboardPath(NULL); $session->setClipboardPathThumb(NULL); $response = $action . ' successful'; $this->r = array($response, 200); }