protected function validateExtension($ext, $type) { $ext = trim(strtolower($ext)); if (!isset($this->types[$type])) { return false; } $exts = strtolower(text::clearWhitespaces($this->config['deniedExts'])); if (strlen($exts)) { $exts = explode(" ", $exts); if (in_array($ext, $exts)) { return false; } } $exts = trim($this->types[$type]); if (!strlen($exts) || substr($exts, 0, 1) == "*") { return true; } if (substr($exts, 0, 1) == "!") { $exts = explode(" ", trim(strtolower(substr($exts, 1)))); return !in_array($ext, $exts); } $exts = explode(" ", trim(strtolower($exts))); return in_array($ext, $exts); }
protected function act_rename() { $dir = $this->postDir(); if (!isset($this->post['dir']) || !isset($this->post['file']) || !isset($this->post['newName']) || false === ($file = "{$dir}/{$this->post['file']}") || !file_exists($file) || !is_readable($file) || !file::isWritable($file)) { $this->errorMsg("Unknown error."); } $newName = text::clearWhitespaces($this->post['newName']); if (!strlen($newName)) { $this->errorMsg("Please enter new file name."); } if (preg_match('/\\//s', $newName)) { $this->errorMsg("Unallowable characters in file name."); } if (substr($newName, 0, 1) == ".") { $this->errorMsg("File name shouldn't begins with '.'"); } $newName = "{$dir}/{$newName}"; if (file_exists($newName)) { $this->errorMsg("A file or folder with that name already exists."); } $ext = file::getExtension($newName); if (!$this->validateExtension($ext, $this->type)) { $this->errorMsg("Denied file extension."); } if (!@rename($file, $newName)) { $this->errorMsg("Unknown error."); } $thumbDir = "{$this->thumbsTypeDir}/{$this->post['dir']}"; $thumbFile = "{$thumbDir}/{$this->post['file']}"; if (file_exists($thumbFile)) { @rename($thumbFile, "{$thumbDir}/" . basename($newName)); } return true; }