Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php defined("\102\x41\x53\105\120\x41\124\x48") or die("\116\157\x20\x64\x69\162\145\14..

Decoded Output download

<?php
 defined("BASEPATH") or die("No direct script access allowed"); class CI_Upload { public $max_size = 0; public $max_width = 0; public $max_height = 0; public $min_width = 0; public $min_height = 0; public $max_filename = 0; public $max_filename_increment = 100; public $allowed_types = ''; public $file_temp = ''; public $file_name = ''; public $orig_name = ''; public $file_type = ''; public $file_size = NULL; public $file_ext = ''; public $file_ext_tolower = FALSE; public $upload_path = ''; public $overwrite = FALSE; public $encrypt_name = FALSE; public $is_image = FALSE; public $image_width = NULL; public $image_height = NULL; public $image_type = ''; public $image_size_str = ''; public $error_msg = array(); public $remove_spaces = TRUE; public $detect_mime = TRUE; public $xss_clean = FALSE; public $mod_mime_fix = TRUE; public $temp_prefix = "temp_file_"; public $client_name = ''; protected $_file_name_override = ''; protected $_mimes = array(); protected $_CI; public function __construct($config = array()) { empty($config) or $this->initialize($config, FALSE); $this->_mimes =& get_mimes(); $this->_CI =& get_instance(); log_message("info", "Upload Class Initialized"); } public function initialize(array $config = array(), $reset = TRUE) { $reflection = new ReflectionClass($this); if ($reset === TRUE) { $defaults = $reflection->getDefaultProperties(); foreach (array_keys($defaults) as $key) { if ($key[0] === "_") { continue; } if (isset($config[$key])) { if ($reflection->hasMethod("set_" . $key)) { $this->{"set_" . $key}($config[$key]); } else { $this->{$key} = $config[$key]; } } else { $this->{$key} = $defaults[$key]; } } } else { foreach ($config as $key => &$value) { if ($key[0] !== "_" && $reflection->hasProperty($key)) { if ($reflection->hasMethod("set_" . $key)) { $this->{"set_" . $key}($value); } else { $this->{$key} = $value; } } } } $this->_file_name_override = $this->file_name; return $this; } public function do_upload($field = "userfile") { if (isset($_FILES[$field])) { $_file = $_FILES[$field]; } elseif (($c = preg_match_all("/(?:^[^\[]+)|\[[^]]*\]/", $field, $matches)) > 1) { $_file = $_FILES; for ($i = 0; $i < $c; $i++) { if (($field = trim($matches[0][$i], "[]")) === '' or !isset($_file[$field])) { $_file = NULL; break; } $_file = $_file[$field]; } } if (!isset($_file)) { $this->set_error("upload_no_file_selected", "debug"); return FALSE; } if (!$this->validate_upload_path()) { return FALSE; } if (!is_uploaded_file($_file["tmp_name"])) { $error = isset($_file["error"]) ? $_file["error"] : 4; switch ($error) { case UPLOAD_ERR_INI_SIZE: $this->set_error("upload_file_exceeds_limit", "info"); break; case UPLOAD_ERR_FORM_SIZE: $this->set_error("upload_file_exceeds_form_limit", "info"); break; case UPLOAD_ERR_PARTIAL: $this->set_error("upload_file_partial", "debug"); break; case UPLOAD_ERR_NO_FILE: $this->set_error("upload_no_file_selected", "debug"); break; case UPLOAD_ERR_NO_TMP_DIR: $this->set_error("upload_no_temp_directory", "error"); break; case UPLOAD_ERR_CANT_WRITE: $this->set_error("upload_unable_to_write_file", "error"); break; case UPLOAD_ERR_EXTENSION: $this->set_error("upload_stopped_by_extension", "debug"); break; default: $this->set_error("upload_no_file_selected", "debug"); break; } return FALSE; } $this->file_temp = $_file["tmp_name"]; $this->file_size = $_file["size"]; if ($this->detect_mime !== FALSE) { $this->_file_mime_type($_file); } $this->file_type = preg_replace("/^(.+?);.*$/", "\1", $this->file_type); $this->file_type = strtolower(trim(stripslashes($this->file_type), """)); $this->file_name = $this->_prep_filename($_file["name"]); $this->file_ext = $this->get_extension($this->file_name); $this->client_name = $this->file_name; if (!$this->is_allowed_filetype()) { $this->set_error("upload_invalid_filetype", "debug"); return FALSE; } if ($this->_file_name_override !== '') { $this->file_name = $this->_prep_filename($this->_file_name_override); if (strpos($this->_file_name_override, ".") === FALSE) { $this->file_name .= $this->file_ext; } else { $this->file_ext = $this->get_extension($this->_file_name_override); } if (!$this->is_allowed_filetype(TRUE)) { $this->set_error("upload_invalid_filetype", "debug"); return FALSE; } } if ($this->file_size > 0) { $this->file_size = round($this->file_size / 1024, 2); } if (!$this->is_allowed_filesize()) { $this->set_error("upload_invalid_filesize", "info"); return FALSE; } if (!$this->is_allowed_dimensions()) { $this->set_error("upload_invalid_dimensions", "info"); return FALSE; } $this->file_name = $this->_CI->security->sanitize_filename($this->file_name); if ($this->max_filename > 0) { $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename); } if ($this->remove_spaces === TRUE) { $this->file_name = preg_replace("/\s+/", "_", $this->file_name); } if ($this->file_ext_tolower && ($ext_length = strlen($this->file_ext))) { $this->file_name = substr($this->file_name, 0, -$ext_length) . $this->file_ext; } $this->orig_name = $this->file_name; if (FALSE === ($this->file_name = $this->set_filename($this->upload_path, $this->file_name))) { return FALSE; } if ($this->xss_clean && $this->do_xss_clean() === FALSE) { $this->set_error("upload_unable_to_write_file", "error"); return FALSE; } if (!@copy($this->file_temp, $this->upload_path . $this->file_name)) { if (!@move_uploaded_file($this->file_temp, $this->upload_path . $this->file_name)) { $this->set_error("upload_destination_error", "error"); return FALSE; } } $this->set_image_properties($this->upload_path . $this->file_name); return TRUE; } public function data($index = NULL) { $data = array("file_name" => $this->file_name, "file_type" => $this->file_type, "file_path" => $this->upload_path, "full_path" => $this->upload_path . $this->file_name, "raw_name" => substr($this->file_name, 0, -strlen($this->file_ext)), "orig_name" => $this->orig_name, "client_name" => $this->client_name, "file_ext" => $this->file_ext, "file_size" => $this->file_size, "is_image" => $this->is_image(), "image_width" => $this->image_width, "image_height" => $this->image_height, "image_type" => $this->image_type, "image_size_str" => $this->image_size_str); if (!empty($index)) { return isset($data[$index]) ? $data[$index] : NULL; } return $data; } public function set_upload_path($path) { $this->upload_path = rtrim($path, "/") . "/"; return $this; } public function set_filename($path, $filename) { if ($this->encrypt_name === TRUE) { $filename = md5(uniqid(mt_rand())) . $this->file_ext; } if ($this->overwrite === TRUE or !file_exists($path . $filename)) { return $filename; } $filename = str_replace($this->file_ext, '', $filename); $new_filename = ''; for ($i = 1; $i < $this->max_filename_increment; $i++) { if (!file_exists($path . $filename . $i . $this->file_ext)) { $new_filename = $filename . $i . $this->file_ext; break; } } if ($new_filename === '') { $this->set_error("upload_bad_filename", "debug"); return FALSE; } return $new_filename; } public function set_max_filesize($n) { $this->max_size = $n < 0 ? 0 : (int) $n; return $this; } protected function set_max_size($n) { return $this->set_max_filesize($n); } public function set_max_filename($n) { $this->max_filename = $n < 0 ? 0 : (int) $n; return $this; } public function set_max_width($n) { $this->max_width = $n < 0 ? 0 : (int) $n; return $this; } public function set_max_height($n) { $this->max_height = $n < 0 ? 0 : (int) $n; return $this; } public function set_min_width($n) { $this->min_width = $n < 0 ? 0 : (int) $n; return $this; } public function set_min_height($n) { $this->min_height = $n < 0 ? 0 : (int) $n; return $this; } public function set_allowed_types($types) { $this->allowed_types = (is_array($types) or $types === "*") ? $types : explode("|", $types); return $this; } public function set_image_properties($path = '') { if ($this->is_image() && function_exists("getimagesize")) { if (FALSE !== ($D = @getimagesize($path))) { $types = array(1 => "gif", 2 => "jpeg", 3 => "png"); $this->image_width = $D[0]; $this->image_height = $D[1]; $this->image_type = isset($types[$D[2]]) ? $types[$D[2]] : "unknown"; $this->image_size_str = $D[3]; } } return $this; } public function set_xss_clean($flag = FALSE) { $this->xss_clean = $flag === TRUE; return $this; } public function is_image() { $png_mimes = array("image/x-png"); $jpeg_mimes = array("image/jpg", "image/jpe", "image/jpeg", "image/pjpeg"); if (in_array($this->file_type, $png_mimes)) { $this->file_type = "image/png"; } elseif (in_array($this->file_type, $jpeg_mimes)) { $this->file_type = "image/jpeg"; } $img_mimes = array("image/gif", "image/jpeg", "image/png", "image/webp"); return in_array($this->file_type, $img_mimes, TRUE); } public function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types === "*") { return TRUE; } if (empty($this->allowed_types) or !is_array($this->allowed_types)) { $this->set_error("upload_no_file_types", "debug"); return FALSE; } $ext = strtolower(ltrim($this->file_ext, ".")); if (!in_array($ext, $this->allowed_types, TRUE)) { return FALSE; } if (in_array($ext, array("gif", "jpg", "jpeg", "jpe", "png", "webp"), TRUE) && @getimagesize($this->file_temp) === FALSE) { return FALSE; } if ($ignore_mime === TRUE) { return TRUE; } if (isset($this->_mimes[$ext])) { return is_array($this->_mimes[$ext]) ? in_array($this->file_type, $this->_mimes[$ext], TRUE) : $this->_mimes[$ext] === $this->file_type; } return FALSE; } public function is_allowed_filesize() { return $this->max_size === 0 or $this->max_size > $this->file_size; } public function is_allowed_dimensions() { if (!$this->is_image()) { return TRUE; } if (function_exists("getimagesize")) { $D = @getimagesize($this->file_temp); if ($this->max_width > 0 && $D[0] > $this->max_width) { return FALSE; } if ($this->max_height > 0 && $D[1] > $this->max_height) { return FALSE; } if ($this->min_width > 0 && $D[0] < $this->min_width) { return FALSE; } if ($this->min_height > 0 && $D[1] < $this->min_height) { return FALSE; } } return TRUE; } public function validate_upload_path() { if ($this->upload_path === '') { $this->set_error("upload_no_filepath", "error"); return FALSE; } if (realpath($this->upload_path) !== FALSE) { $this->upload_path = str_replace("\", "/", realpath($this->upload_path)); } if (!is_dir($this->upload_path)) { $this->set_error("upload_no_filepath", "error"); return FALSE; } if (!is_really_writable($this->upload_path)) { $this->set_error("upload_not_writable", "error"); return FALSE; } $this->upload_path = preg_replace("/(.+?)\/*$/", "\1/", $this->upload_path); return TRUE; } public function get_extension($filename) { $x = explode(".", $filename); if (count($x) === 1) { return ''; } $ext = $this->file_ext_tolower ? strtolower(end($x)) : end($x); return "." . $ext; } public function limit_filename_length($filename, $length) { if (strlen($filename) < $length) { return $filename; } $ext = ''; if (strpos($filename, ".") !== FALSE) { $parts = explode(".", $filename); $ext = "." . array_pop($parts); $filename = implode(".", $parts); } return substr($filename, 0, $length - strlen($ext)) . $ext; } public function do_xss_clean() { $file = $this->file_temp; if (filesize($file) == 0) { return FALSE; } if (memory_get_usage() && ($memory_limit = ini_get("memory_limit")) > 0) { $memory_limit = str_split($memory_limit, strspn($memory_limit, "1234567890")); if (!empty($memory_limit[1])) { switch ($memory_limit[1][0]) { case "g": case "G": $memory_limit[0] *= 1024 * 1024 * 1024; break; case "m": case "M": $memory_limit[0] *= 1024 * 1024; break; default: break; } } $memory_limit = (int) ceil(filesize($file) + $memory_limit[0]); ini_set("memory_limit", $memory_limit); } if (function_exists("getimagesize") && @getimagesize($file) !== FALSE) { if (($file = @fopen($file, "rb")) === FALSE) { return FALSE; } $opening_bytes = fread($file, 256); fclose($file); return !preg_match("/<(a|body|head|html|img|plaintext|pre|script|table|title)[\s>]/i", $opening_bytes); } if (($data = @file_get_contents($file)) === FALSE) { return FALSE; } return $this->_CI->security->xss_clean($data, TRUE); } public function set_error($msg, $log_level = "error") { $this->_CI->lang->load("upload"); is_array($msg) or $msg = array($msg); foreach ($msg as $val) { $msg = $this->_CI->lang->line($val) === FALSE ? $val : $this->_CI->lang->line($val); $this->error_msg[] = $msg; log_message($log_level, $msg); } return $this; } public function display_errors($open = "<p>", $close = "</p>") { return count($this->error_msg) > 0 ? $open . implode($close . $open, $this->error_msg) . $close : ''; } protected function _prep_filename($filename) { if ($this->mod_mime_fix === FALSE or $this->allowed_types === "*" or ($ext_pos = strrpos($filename, ".")) === FALSE) { return $filename; } $ext = substr($filename, $ext_pos); $filename = substr($filename, 0, $ext_pos); return str_replace(".", "_", $filename) . $ext; } protected function _file_mime_type($file) { $regexp = "/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/"; if (function_exists("finfo_file")) { $finfo = @finfo_open(FILEINFO_MIME); if ($finfo !== FALSE) { $mime = @finfo_file($finfo, $file["tmp_name"]); finfo_close($finfo); if (is_string($mime) && preg_match($regexp, $mime, $matches)) { $this->file_type = $matches[1]; return; } } } if (DIRECTORY_SEPARATOR !== "\") { $cmd = "file --brief --mime " . escapeshellarg($file["tmp_name"]) . " 2>&1"; if (function_usable("exec")) { $mime = @exec($cmd, $mime, $return_status); if ($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches)) { $this->file_type = $matches[1]; return; } } if (function_usable("shell_exec")) { $mime = @shell_exec($cmd); if (strlen($mime) > 0) { $mime = explode("
", trim($mime)); if (preg_match($regexp, $mime[count($mime) - 1], $matches)) { $this->file_type = $matches[1]; return; } } } if (function_usable("popen")) { $proc = @popen($cmd, "r"); if (is_resource($proc)) { $mime = @fread($proc, 512); @pclose($proc); if ($mime !== FALSE) { $mime = explode("\xa", trim($mime)); if (preg_match($regexp, $mime[count($mime) - 1], $matches)) { $this->file_type = $matches[1]; return; } } } } } if (function_exists("mime_content_type")) { $this->file_type = @mime_content_type($file["tmp_name"]); if (strlen($this->file_type) > 0) { return; } } $this->file_type = $file["type"]; } } ?>

Did this file decode correctly?

Original Code

<?php
 defined("\102\x41\x53\105\120\x41\124\x48") or die("\116\157\x20\x64\x69\162\145\143\164\40\x73\x63\x72\151\160\x74\40\141\143\x63\145\163\163\x20\141\x6c\x6c\157\167\145\144"); class CI_Upload { public $max_size = 0; public $max_width = 0; public $max_height = 0; public $min_width = 0; public $min_height = 0; public $max_filename = 0; public $max_filename_increment = 100; public $allowed_types = ''; public $file_temp = ''; public $file_name = ''; public $orig_name = ''; public $file_type = ''; public $file_size = NULL; public $file_ext = ''; public $file_ext_tolower = FALSE; public $upload_path = ''; public $overwrite = FALSE; public $encrypt_name = FALSE; public $is_image = FALSE; public $image_width = NULL; public $image_height = NULL; public $image_type = ''; public $image_size_str = ''; public $error_msg = array(); public $remove_spaces = TRUE; public $detect_mime = TRUE; public $xss_clean = FALSE; public $mod_mime_fix = TRUE; public $temp_prefix = "\164\145\x6d\x70\137\146\151\x6c\x65\137"; public $client_name = ''; protected $_file_name_override = ''; protected $_mimes = array(); protected $_CI; public function __construct($config = array()) { empty($config) or $this->initialize($config, FALSE); $this->_mimes =& get_mimes(); $this->_CI =& get_instance(); log_message("\x69\156\x66\x6f", "\x55\160\x6c\x6f\x61\144\40\x43\x6c\x61\163\163\x20\111\156\x69\164\151\x61\x6c\x69\172\x65\144"); } public function initialize(array $config = array(), $reset = TRUE) { $reflection = new ReflectionClass($this); if ($reset === TRUE) { $defaults = $reflection->getDefaultProperties(); foreach (array_keys($defaults) as $key) { if ($key[0] === "\x5f") { continue; } if (isset($config[$key])) { if ($reflection->hasMethod("\163\x65\x74\137" . $key)) { $this->{"\x73\x65\x74\x5f" . $key}($config[$key]); } else { $this->{$key} = $config[$key]; } } else { $this->{$key} = $defaults[$key]; } } } else { foreach ($config as $key => &$value) { if ($key[0] !== "\x5f" && $reflection->hasProperty($key)) { if ($reflection->hasMethod("\x73\145\x74\x5f" . $key)) { $this->{"\x73\x65\x74\137" . $key}($value); } else { $this->{$key} = $value; } } } } $this->_file_name_override = $this->file_name; return $this; } public function do_upload($field = "\165\x73\145\x72\x66\151\x6c\145") { if (isset($_FILES[$field])) { $_file = $_FILES[$field]; } elseif (($c = preg_match_all("\x2f\50\77\72\x5e\x5b\136\134\x5b\135\x2b\51\x7c\134\x5b\x5b\136\x5d\135\x2a\134\x5d\x2f", $field, $matches)) > 1) { $_file = $_FILES; for ($i = 0; $i < $c; $i++) { if (($field = trim($matches[0][$i], "\133\x5d")) === '' or !isset($_file[$field])) { $_file = NULL; break; } $_file = $_file[$field]; } } if (!isset($_file)) { $this->set_error("\165\x70\x6c\157\141\144\x5f\x6e\x6f\x5f\146\x69\x6c\x65\x5f\163\145\154\x65\143\x74\x65\144", "\144\x65\x62\165\147"); return FALSE; } if (!$this->validate_upload_path()) { return FALSE; } if (!is_uploaded_file($_file["\x74\155\x70\x5f\x6e\141\155\145"])) { $error = isset($_file["\145\162\162\157\162"]) ? $_file["\x65\x72\x72\157\x72"] : 4; switch ($error) { case UPLOAD_ERR_INI_SIZE: $this->set_error("\165\160\154\x6f\141\144\x5f\146\x69\x6c\145\x5f\x65\170\143\145\145\x64\163\x5f\154\x69\155\x69\x74", "\x69\x6e\146\x6f"); break; case UPLOAD_ERR_FORM_SIZE: $this->set_error("\165\160\154\157\141\144\137\146\151\x6c\145\x5f\x65\170\x63\145\x65\x64\163\x5f\x66\x6f\x72\x6d\137\154\151\155\151\164", "\x69\x6e\146\157"); break; case UPLOAD_ERR_PARTIAL: $this->set_error("\165\x70\154\x6f\x61\144\137\x66\151\154\145\137\160\x61\x72\164\x69\141\x6c", "\x64\x65\142\x75\x67"); break; case UPLOAD_ERR_NO_FILE: $this->set_error("\165\x70\x6c\157\141\144\137\156\x6f\137\146\151\x6c\145\x5f\163\145\x6c\145\143\x74\145\144", "\x64\x65\142\165\147"); break; case UPLOAD_ERR_NO_TMP_DIR: $this->set_error("\x75\160\154\157\141\x64\x5f\x6e\x6f\x5f\x74\145\155\160\x5f\144\151\x72\145\143\x74\157\162\171", "\145\x72\162\x6f\x72"); break; case UPLOAD_ERR_CANT_WRITE: $this->set_error("\165\x70\x6c\157\x61\144\137\x75\x6e\141\x62\x6c\x65\137\x74\157\x5f\x77\162\151\164\145\x5f\146\151\154\145", "\145\x72\x72\157\162"); break; case UPLOAD_ERR_EXTENSION: $this->set_error("\x75\x70\x6c\x6f\141\144\x5f\163\164\x6f\160\x70\x65\144\137\142\171\137\145\x78\164\x65\156\163\151\x6f\x6e", "\144\145\x62\x75\x67"); break; default: $this->set_error("\x75\x70\154\157\141\144\x5f\x6e\x6f\137\146\x69\x6c\145\137\x73\x65\154\145\143\x74\145\x64", "\144\145\142\165\147"); break; } return FALSE; } $this->file_temp = $_file["\164\x6d\160\137\156\141\x6d\x65"]; $this->file_size = $_file["\163\x69\172\145"]; if ($this->detect_mime !== FALSE) { $this->_file_mime_type($_file); } $this->file_type = preg_replace("\x2f\x5e\x28\56\53\77\51\x3b\x2e\x2a\44\57", "\134\61", $this->file_type); $this->file_type = strtolower(trim(stripslashes($this->file_type), "\x22")); $this->file_name = $this->_prep_filename($_file["\156\x61\155\x65"]); $this->file_ext = $this->get_extension($this->file_name); $this->client_name = $this->file_name; if (!$this->is_allowed_filetype()) { $this->set_error("\165\160\154\157\x61\144\x5f\x69\156\166\141\154\151\x64\137\x66\x69\x6c\145\x74\x79\160\145", "\144\145\142\x75\x67"); return FALSE; } if ($this->_file_name_override !== '') { $this->file_name = $this->_prep_filename($this->_file_name_override); if (strpos($this->_file_name_override, "\x2e") === FALSE) { $this->file_name .= $this->file_ext; } else { $this->file_ext = $this->get_extension($this->_file_name_override); } if (!$this->is_allowed_filetype(TRUE)) { $this->set_error("\x75\x70\x6c\x6f\141\x64\x5f\151\x6e\x76\141\154\x69\x64\x5f\x66\151\154\x65\164\x79\x70\x65", "\144\x65\x62\165\x67"); return FALSE; } } if ($this->file_size > 0) { $this->file_size = round($this->file_size / 1024, 2); } if (!$this->is_allowed_filesize()) { $this->set_error("\x75\x70\154\x6f\x61\144\x5f\x69\x6e\166\x61\154\151\x64\x5f\x66\151\x6c\145\x73\x69\x7a\x65", "\x69\x6e\146\x6f"); return FALSE; } if (!$this->is_allowed_dimensions()) { $this->set_error("\x75\160\x6c\x6f\141\144\x5f\151\x6e\166\141\x6c\x69\144\x5f\144\x69\155\x65\x6e\x73\x69\x6f\156\x73", "\x69\x6e\146\x6f"); return FALSE; } $this->file_name = $this->_CI->security->sanitize_filename($this->file_name); if ($this->max_filename > 0) { $this->file_name = $this->limit_filename_length($this->file_name, $this->max_filename); } if ($this->remove_spaces === TRUE) { $this->file_name = preg_replace("\x2f\134\163\53\x2f", "\x5f", $this->file_name); } if ($this->file_ext_tolower && ($ext_length = strlen($this->file_ext))) { $this->file_name = substr($this->file_name, 0, -$ext_length) . $this->file_ext; } $this->orig_name = $this->file_name; if (FALSE === ($this->file_name = $this->set_filename($this->upload_path, $this->file_name))) { return FALSE; } if ($this->xss_clean && $this->do_xss_clean() === FALSE) { $this->set_error("\165\x70\x6c\157\x61\144\137\x75\x6e\141\142\154\145\137\164\157\x5f\167\162\151\x74\x65\137\146\151\154\145", "\145\162\162\157\162"); return FALSE; } if (!@copy($this->file_temp, $this->upload_path . $this->file_name)) { if (!@move_uploaded_file($this->file_temp, $this->upload_path . $this->file_name)) { $this->set_error("\165\x70\x6c\157\141\x64\x5f\144\x65\163\164\x69\156\141\x74\151\157\156\137\145\162\162\x6f\162", "\x65\162\162\x6f\x72"); return FALSE; } } $this->set_image_properties($this->upload_path . $this->file_name); return TRUE; } public function data($index = NULL) { $data = array("\x66\x69\154\145\137\156\141\x6d\145" => $this->file_name, "\x66\151\x6c\145\137\164\171\160\145" => $this->file_type, "\x66\x69\x6c\x65\x5f\x70\141\x74\150" => $this->upload_path, "\x66\165\x6c\154\x5f\x70\x61\164\x68" => $this->upload_path . $this->file_name, "\x72\141\167\137\156\x61\x6d\x65" => substr($this->file_name, 0, -strlen($this->file_ext)), "\157\x72\x69\x67\x5f\156\x61\155\x65" => $this->orig_name, "\143\154\x69\x65\x6e\164\137\156\141\x6d\145" => $this->client_name, "\x66\151\x6c\x65\x5f\145\x78\x74" => $this->file_ext, "\x66\151\x6c\145\137\163\x69\172\145" => $this->file_size, "\x69\163\x5f\x69\x6d\141\x67\145" => $this->is_image(), "\x69\x6d\141\x67\x65\x5f\167\x69\144\164\x68" => $this->image_width, "\x69\155\x61\x67\145\137\x68\x65\151\147\150\164" => $this->image_height, "\x69\155\141\147\x65\137\164\171\x70\145" => $this->image_type, "\151\x6d\x61\147\x65\x5f\163\151\x7a\x65\137\163\164\162" => $this->image_size_str); if (!empty($index)) { return isset($data[$index]) ? $data[$index] : NULL; } return $data; } public function set_upload_path($path) { $this->upload_path = rtrim($path, "\57") . "\x2f"; return $this; } public function set_filename($path, $filename) { if ($this->encrypt_name === TRUE) { $filename = md5(uniqid(mt_rand())) . $this->file_ext; } if ($this->overwrite === TRUE or !file_exists($path . $filename)) { return $filename; } $filename = str_replace($this->file_ext, '', $filename); $new_filename = ''; for ($i = 1; $i < $this->max_filename_increment; $i++) { if (!file_exists($path . $filename . $i . $this->file_ext)) { $new_filename = $filename . $i . $this->file_ext; break; } } if ($new_filename === '') { $this->set_error("\165\x70\154\157\141\x64\x5f\x62\141\144\x5f\146\151\x6c\145\156\141\x6d\145", "\144\x65\x62\165\x67"); return FALSE; } return $new_filename; } public function set_max_filesize($n) { $this->max_size = $n < 0 ? 0 : (int) $n; return $this; } protected function set_max_size($n) { return $this->set_max_filesize($n); } public function set_max_filename($n) { $this->max_filename = $n < 0 ? 0 : (int) $n; return $this; } public function set_max_width($n) { $this->max_width = $n < 0 ? 0 : (int) $n; return $this; } public function set_max_height($n) { $this->max_height = $n < 0 ? 0 : (int) $n; return $this; } public function set_min_width($n) { $this->min_width = $n < 0 ? 0 : (int) $n; return $this; } public function set_min_height($n) { $this->min_height = $n < 0 ? 0 : (int) $n; return $this; } public function set_allowed_types($types) { $this->allowed_types = (is_array($types) or $types === "\52") ? $types : explode("\174", $types); return $this; } public function set_image_properties($path = '') { if ($this->is_image() && function_exists("\147\x65\164\x69\155\141\x67\145\x73\x69\172\x65")) { if (FALSE !== ($D = @getimagesize($path))) { $types = array(1 => "\x67\x69\146", 2 => "\x6a\x70\x65\147", 3 => "\x70\156\147"); $this->image_width = $D[0]; $this->image_height = $D[1]; $this->image_type = isset($types[$D[2]]) ? $types[$D[2]] : "\165\156\153\x6e\157\167\x6e"; $this->image_size_str = $D[3]; } } return $this; } public function set_xss_clean($flag = FALSE) { $this->xss_clean = $flag === TRUE; return $this; } public function is_image() { $png_mimes = array("\151\155\141\147\145\x2f\x78\x2d\x70\156\147"); $jpeg_mimes = array("\151\155\x61\147\145\x2f\x6a\x70\147", "\x69\155\x61\147\145\x2f\x6a\x70\145", "\151\155\x61\x67\145\57\152\x70\145\x67", "\x69\x6d\x61\147\145\x2f\160\x6a\x70\145\x67"); if (in_array($this->file_type, $png_mimes)) { $this->file_type = "\x69\x6d\x61\147\145\57\x70\x6e\147"; } elseif (in_array($this->file_type, $jpeg_mimes)) { $this->file_type = "\x69\155\x61\x67\x65\x2f\x6a\x70\145\147"; } $img_mimes = array("\151\x6d\x61\147\145\57\x67\151\x66", "\x69\x6d\x61\x67\x65\57\x6a\x70\x65\x67", "\151\155\x61\147\145\x2f\160\x6e\x67", "\x69\155\x61\x67\x65\x2f\167\145\142\x70"); return in_array($this->file_type, $img_mimes, TRUE); } public function is_allowed_filetype($ignore_mime = FALSE) { if ($this->allowed_types === "\52") { return TRUE; } if (empty($this->allowed_types) or !is_array($this->allowed_types)) { $this->set_error("\x75\160\x6c\x6f\141\144\137\x6e\157\x5f\x66\x69\x6c\145\137\164\171\x70\x65\x73", "\x64\x65\x62\x75\147"); return FALSE; } $ext = strtolower(ltrim($this->file_ext, "\x2e")); if (!in_array($ext, $this->allowed_types, TRUE)) { return FALSE; } if (in_array($ext, array("\147\x69\x66", "\x6a\x70\x67", "\152\160\145\x67", "\152\160\x65", "\160\x6e\x67", "\x77\145\142\x70"), TRUE) && @getimagesize($this->file_temp) === FALSE) { return FALSE; } if ($ignore_mime === TRUE) { return TRUE; } if (isset($this->_mimes[$ext])) { return is_array($this->_mimes[$ext]) ? in_array($this->file_type, $this->_mimes[$ext], TRUE) : $this->_mimes[$ext] === $this->file_type; } return FALSE; } public function is_allowed_filesize() { return $this->max_size === 0 or $this->max_size > $this->file_size; } public function is_allowed_dimensions() { if (!$this->is_image()) { return TRUE; } if (function_exists("\147\145\x74\151\x6d\x61\x67\145\x73\x69\172\x65")) { $D = @getimagesize($this->file_temp); if ($this->max_width > 0 && $D[0] > $this->max_width) { return FALSE; } if ($this->max_height > 0 && $D[1] > $this->max_height) { return FALSE; } if ($this->min_width > 0 && $D[0] < $this->min_width) { return FALSE; } if ($this->min_height > 0 && $D[1] < $this->min_height) { return FALSE; } } return TRUE; } public function validate_upload_path() { if ($this->upload_path === '') { $this->set_error("\x75\x70\x6c\x6f\141\x64\x5f\156\157\x5f\x66\x69\154\145\160\x61\x74\150", "\x65\x72\x72\x6f\x72"); return FALSE; } if (realpath($this->upload_path) !== FALSE) { $this->upload_path = str_replace("\134", "\57", realpath($this->upload_path)); } if (!is_dir($this->upload_path)) { $this->set_error("\165\160\x6c\157\141\x64\137\x6e\157\x5f\x66\x69\x6c\145\x70\141\x74\150", "\145\x72\x72\157\x72"); return FALSE; } if (!is_really_writable($this->upload_path)) { $this->set_error("\165\x70\154\x6f\x61\x64\137\156\x6f\x74\x5f\x77\x72\x69\164\141\x62\154\145", "\x65\162\162\x6f\x72"); return FALSE; } $this->upload_path = preg_replace("\57\x28\x2e\x2b\x3f\51\x5c\x2f\x2a\44\x2f", "\x5c\61\57", $this->upload_path); return TRUE; } public function get_extension($filename) { $x = explode("\x2e", $filename); if (count($x) === 1) { return ''; } $ext = $this->file_ext_tolower ? strtolower(end($x)) : end($x); return "\56" . $ext; } public function limit_filename_length($filename, $length) { if (strlen($filename) < $length) { return $filename; } $ext = ''; if (strpos($filename, "\56") !== FALSE) { $parts = explode("\x2e", $filename); $ext = "\56" . array_pop($parts); $filename = implode("\x2e", $parts); } return substr($filename, 0, $length - strlen($ext)) . $ext; } public function do_xss_clean() { $file = $this->file_temp; if (filesize($file) == 0) { return FALSE; } if (memory_get_usage() && ($memory_limit = ini_get("\155\x65\155\x6f\162\171\x5f\154\151\x6d\151\x74")) > 0) { $memory_limit = str_split($memory_limit, strspn($memory_limit, "\61\62\x33\64\65\x36\67\x38\71\60")); if (!empty($memory_limit[1])) { switch ($memory_limit[1][0]) { case "\x67": case "\x47": $memory_limit[0] *= 1024 * 1024 * 1024; break; case "\x6d": case "\x4d": $memory_limit[0] *= 1024 * 1024; break; default: break; } } $memory_limit = (int) ceil(filesize($file) + $memory_limit[0]); ini_set("\155\x65\x6d\x6f\162\x79\x5f\x6c\x69\155\x69\164", $memory_limit); } if (function_exists("\147\x65\x74\151\x6d\141\147\x65\163\151\x7a\145") && @getimagesize($file) !== FALSE) { if (($file = @fopen($file, "\x72\x62")) === FALSE) { return FALSE; } $opening_bytes = fread($file, 256); fclose($file); return !preg_match("\57\x3c\50\x61\174\x62\157\x64\171\x7c\x68\x65\x61\144\174\x68\164\x6d\154\174\151\155\x67\x7c\160\154\x61\151\x6e\164\145\170\x74\174\x70\x72\x65\174\x73\x63\162\151\x70\x74\174\164\141\x62\154\x65\174\164\151\164\154\x65\x29\133\134\163\x3e\x5d\57\151", $opening_bytes); } if (($data = @file_get_contents($file)) === FALSE) { return FALSE; } return $this->_CI->security->xss_clean($data, TRUE); } public function set_error($msg, $log_level = "\x65\162\x72\157\x72") { $this->_CI->lang->load("\x75\x70\154\157\x61\144"); is_array($msg) or $msg = array($msg); foreach ($msg as $val) { $msg = $this->_CI->lang->line($val) === FALSE ? $val : $this->_CI->lang->line($val); $this->error_msg[] = $msg; log_message($log_level, $msg); } return $this; } public function display_errors($open = "\74\x70\76", $close = "\x3c\57\x70\76") { return count($this->error_msg) > 0 ? $open . implode($close . $open, $this->error_msg) . $close : ''; } protected function _prep_filename($filename) { if ($this->mod_mime_fix === FALSE or $this->allowed_types === "\52" or ($ext_pos = strrpos($filename, "\56")) === FALSE) { return $filename; } $ext = substr($filename, $ext_pos); $filename = substr($filename, 0, $ext_pos); return str_replace("\56", "\137", $filename) . $ext; } protected function _file_mime_type($file) { $regexp = "\x2f\136\x28\x5b\141\55\x7a\x5c\55\135\53\x5c\57\x5b\141\55\x7a\x30\x2d\x39\x5c\55\x5c\x2e\134\53\135\x2b\x29\x28\73\x5c\163\x2e\53\x29\77\44\x2f"; if (function_exists("\x66\151\x6e\146\x6f\x5f\x66\x69\154\145")) { $finfo = @finfo_open(FILEINFO_MIME); if ($finfo !== FALSE) { $mime = @finfo_file($finfo, $file["\x74\155\160\x5f\156\x61\x6d\x65"]); finfo_close($finfo); if (is_string($mime) && preg_match($regexp, $mime, $matches)) { $this->file_type = $matches[1]; return; } } } if (DIRECTORY_SEPARATOR !== "\134") { $cmd = "\146\x69\x6c\x65\40\55\55\x62\x72\x69\x65\146\40\x2d\55\155\x69\x6d\145\x20" . escapeshellarg($file["\x74\x6d\160\x5f\x6e\141\155\145"]) . "\x20\x32\x3e\46\61"; if (function_usable("\x65\x78\x65\143")) { $mime = @exec($cmd, $mime, $return_status); if ($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches)) { $this->file_type = $matches[1]; return; } } if (function_usable("\x73\150\145\x6c\154\x5f\x65\x78\x65\143")) { $mime = @shell_exec($cmd); if (strlen($mime) > 0) { $mime = explode("\12", trim($mime)); if (preg_match($regexp, $mime[count($mime) - 1], $matches)) { $this->file_type = $matches[1]; return; } } } if (function_usable("\160\157\160\x65\x6e")) { $proc = @popen($cmd, "\162"); if (is_resource($proc)) { $mime = @fread($proc, 512); @pclose($proc); if ($mime !== FALSE) { $mime = explode("\xa", trim($mime)); if (preg_match($regexp, $mime[count($mime) - 1], $matches)) { $this->file_type = $matches[1]; return; } } } } } if (function_exists("\155\151\x6d\145\x5f\143\x6f\156\164\145\156\x74\137\x74\171\x70\x65")) { $this->file_type = @mime_content_type($file["\x74\155\x70\x5f\156\x61\155\145"]); if (strlen($this->file_type) > 0) { return; } } $this->file_type = $file["\x74\171\x70\145"]; } }

Function Calls

None

Variables

None

Stats

MD5 f8412bc176e70121dd05e270c62bd6a8
Eval Count 0
Decode Time 105 ms