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 class UploadHandler { protected $options; protected $error_messages = array(1 => "\..

Decoded Output download

<?php
 class UploadHandler { protected $options; protected $error_messages = array(1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini", 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3 => "The uploaded file was only partially uploaded", 4 => "No file was uploaded", 6 => "Missing a temporary folder", 7 => "Failed to write file to disk", 8 => "A PHP extension stopped the file upload", "post_max_size" => "The uploaded file exceeds the post_max_size directive in php.ini", "max_file_size" => "File is too big", "min_file_size" => "File is too small", "accept_file_types" => "Filetype not allowed", "max_number_of_files" => "Maximum number of files exceeded", "invalid_file_type" => "Invalid file type", "max_width" => "Image exceeds maximum width", "min_width" => "Image requires a minimum width", "max_height" => "Image exceeds maximum height", "min_height" => "Image requires a minimum height", "abort" => "File upload aborted", "image_resize" => "Failed to resize image"); const IMAGETYPE_GIF = "image/gif"; const IMAGETYPE_JPEG = "image/jpeg"; const IMAGETYPE_PNG = "image/png"; protected $image_objects = array(); protected $response = array(); public function __construct($options = null, $initialize = true, $error_messages = null) { $this->options = array("script_url" => $this->get_full_url() . "/" . $this->basename($this->get_server_var("SCRIPT_NAME")), "upload_dir" => dirname($this->get_server_var("SCRIPT_FILENAME")) . "/files/", "upload_url" => $this->get_full_url() . "/files/", "input_stream" => "php://input", "user_dirs" => false, "mkdir_mode" => 493, "param_name" => "files", "delete_type" => "DELETE", "access_control_allow_origin" => "*", "access_control_allow_credentials" => false, "access_control_allow_methods" => array("OPTIONS", "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE"), "access_control_allow_headers" => array("Content-Type", "Content-Range", "Content-Disposition"), "redirect_allow_target" => "/^" . preg_quote(parse_url($this->get_server_var("HTTP_REFERER"), PHP_URL_SCHEME) . "://" . parse_url($this->get_server_var("HTTP_REFERER"), PHP_URL_HOST) . "/", "/") . "/", "download_via_php" => false, "readfile_chunk_size" => 10 * 1024 * 1024, "inline_file_types" => "/\.(gif|jpe?g|png)$/i", "accept_file_types" => "/\.(gif|jpe?g|png)$/i", "replace_dots_in_filenames" => "-", "max_file_size" => null, "min_file_size" => 1, "max_number_of_files" => null, "correct_image_extensions" => false, "max_width" => null, "max_height" => null, "min_width" => 1, "min_height" => 1, "discard_aborted_uploads" => true, "image_library" => 1, "convert_bin" => "convert", "identify_bin" => "identify", "image_versions" => array('' => array("auto_orient" => true), "thumbnail" => array("max_width" => 80, "max_height" => 80)), "print_response" => true); if ($options) { $this->options = $options + $this->options; } if ($error_messages) { $this->error_messages = $error_messages + $this->error_messages; } if ($initialize) { $this->initialize(); } } protected function initialize() { switch ($this->get_server_var("REQUEST_METHOD")) { case "OPTIONS": case "HEAD": $this->head(); break; case "GET": $this->get($this->options["print_response"]); break; case "PATCH": case "PUT": case "POST": $this->post($this->options["print_response"]); break; case "DELETE": $this->delete($this->options["print_response"]); break; default: $this->header("HTTP/1.1 405 Method Not Allowed"); } } protected function get_full_url() { $https = !empty($_SERVER["HTTPS"]) && strcasecmp($_SERVER["HTTPS"], "on") === 0 || !empty($_SERVER["HTTP_X_FORWARDED_PROTO"]) && strcasecmp($_SERVER["HTTP_X_FORWARDED_PROTO"], "https") === 0; return ($https ? "https://" : "http://") . (!empty($_SERVER["REMOTE_USER"]) ? $_SERVER["REMOTE_USER"] . "@" : '') . (isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"] . ($https && $_SERVER["SERVER_PORT"] === 443 || $_SERVER["SERVER_PORT"] === 80 ? '' : ":" . $_SERVER["SERVER_PORT"])) . substr($_SERVER["SCRIPT_NAME"], 0, strrpos($_SERVER["SCRIPT_NAME"], "/")); } protected function get_user_id() { @session_start(); return session_id(); } protected function get_user_path() { if ($this->options["user_dirs"]) { return $this->get_user_id() . "/"; } return ''; } protected function get_upload_path($file_name = null, $version = null) { $file_name = $file_name ? $file_name : ''; if (empty($version)) { $version_path = ''; } else { $version_dir = @$this->options["image_versions"][$version]["upload_dir"]; if ($version_dir) { return $version_dir . $this->get_user_path() . $file_name; } $version_path = $version . "/"; } return $this->options["upload_dir"] . $this->get_user_path() . $version_path . $file_name; } protected function get_query_separator($url) { return strpos($url, "?") === false ? "?" : "&"; } protected function get_download_url($file_name, $version = null, $direct = false) { if (!$direct && $this->options["download_via_php"]) { $url = $this->options["script_url"] . $this->get_query_separator($this->options["script_url"]) . $this->get_singular_param_name() . "=" . rawurlencode($file_name); if ($version) { $url .= "&version=" . rawurlencode($version); } return $url . "&download=1"; } if (empty($version)) { $version_path = ''; } else { $version_url = @$this->options["image_versions"][$version]["upload_url"]; if ($version_url) { return $version_url . $this->get_user_path() . rawurlencode($file_name); } $version_path = rawurlencode($version) . "/"; } return $this->options["upload_url"] . $this->get_user_path() . $version_path . rawurlencode($file_name); } protected function set_additional_file_properties($file) { $file->deleteUrl = $this->options["script_url"] . $this->get_query_separator($this->options["script_url"]) . $this->get_singular_param_name() . "=" . rawurlencode($file->name); $file->deleteType = $this->options["delete_type"]; if ($file->deleteType !== "DELETE") { $file->deleteUrl .= "&_method=DELETE"; } if ($this->options["access_control_allow_credentials"]) { $file->deleteWithCredentials = true; } } protected function fix_integer_overflow($size) { if ($size < 0) { $size += 2.0 * (PHP_INT_MAX + 1); } return $size; } protected function get_file_size($file_path, $clear_stat_cache = false) { if ($clear_stat_cache) { if (version_compare(PHP_VERSION, "5.3.0") >= 0) { clearstatcache(true, $file_path); } else { clearstatcache(); } } return $this->fix_integer_overflow(filesize($file_path)); } protected function is_valid_file_object($file_name) { $file_path = $this->get_upload_path($file_name); if (strlen($file_name) > 0 && $file_name[0] !== "." && is_file($file_path)) { return true; } return false; } protected function get_file_object($file_name) { if ($this->is_valid_file_object($file_name)) { $file = new \stdClass(); $file->name = $file_name; $file->size = $this->get_file_size($this->get_upload_path($file_name)); $file->url = $this->get_download_url($file->name); foreach ($this->options["image_versions"] as $version => $options) { if (!empty($version)) { if (is_file($this->get_upload_path($file_name, $version))) { $file->{$version . "Url"} = $this->get_download_url($file->name, $version); } } } $this->set_additional_file_properties($file); return $file; } return null; } protected function get_file_objects($iteration_method = "get_file_object") { $upload_dir = $this->get_upload_path(); if (!is_dir($upload_dir)) { return array(); } return array_values(array_filter(array_map(array($this, $iteration_method), scandir($upload_dir)))); } protected function count_file_objects() { return count($this->get_file_objects("is_valid_file_object")); } protected function get_error_message($error) { return isset($this->error_messages[$error]) ? $this->error_messages[$error] : $error; } public function get_config_bytes($val) { $val = trim($val); $last = strtolower($val[strlen($val) - 1]); if (is_numeric($val)) { $val = (int) $val; } else { $val = (int) substr($val, 0, -1); } switch ($last) { case "g": $val *= 1024; case "m": $val *= 1024; case "k": $val *= 1024; } return $this->fix_integer_overflow($val); } protected function validate_image_file($uploaded_file, $file, $error, $index) { if ($this->imagetype($uploaded_file) !== $this->get_file_type($file->name)) { $file->error = $this->get_error_message("invalid_file_type"); return false; } $max_width = @$this->options["max_width"]; $max_height = @$this->options["max_height"]; $min_width = @$this->options["min_width"]; $min_height = @$this->options["min_height"]; if ($max_width || $max_height || $min_width || $min_height) { list($img_width, $img_height) = $this->get_image_size($uploaded_file); if (@$this->options["image_versions"]['']["auto_orient"] && function_exists("exif_read_data") && ($exif = @exif_read_data($uploaded_file)) && (int) @$exif["Orientation"] >= 5) { $tmp = $img_width; $img_width = $img_height; $img_height = $tmp; unset($tmp); } if (!empty($img_width) && !empty($img_height)) { if ($max_width && $img_width > $max_width) { $file->error = $this->get_error_message("max_width"); return false; } if ($max_height && $img_height > $max_height) { $file->error = $this->get_error_message("max_height"); return false; } if ($min_width && $img_width < $min_width) { $file->error = $this->get_error_message("min_width"); return false; } if ($min_height && $img_height < $min_height) { $file->error = $this->get_error_message("min_height"); return false; } } } return true; } protected function validate($uploaded_file, $file, $error, $index, $content_range) { if ($error) { $file->error = $this->get_error_message($error); return false; } $content_length = $this->fix_integer_overflow((int) $this->get_server_var("CONTENT_LENGTH")); $post_max_size = $this->get_config_bytes(ini_get("post_max_size")); if ($post_max_size && $content_length > $post_max_size) { $file->error = $this->get_error_message("post_max_size"); return false; } if (!preg_match($this->options["accept_file_types"], $file->name)) { $file->error = $this->get_error_message("accept_file_types"); return false; } if ($uploaded_file && is_uploaded_file($uploaded_file)) { $file_size = $this->get_file_size($uploaded_file); } else { $file_size = $content_length; } if ($this->options["max_file_size"] && ($file_size > $this->options["max_file_size"] || $file->size > $this->options["max_file_size"])) { $file->error = $this->get_error_message("max_file_size"); return false; } if ($this->options["min_file_size"] && $file_size < $this->options["min_file_size"]) { $file->error = $this->get_error_message("min_file_size"); return false; } if (is_int($this->options["max_number_of_files"]) && $this->count_file_objects() >= $this->options["max_number_of_files"] && !is_file($this->get_upload_path($file->name))) { $file->error = $this->get_error_message("max_number_of_files"); return false; } if (!$content_range && $this->has_image_file_extension($file->name)) { return $this->validate_image_file($uploaded_file, $file, $error, $index); } return true; } protected function upcount_name_callback($matches) { $index = isset($matches[1]) ? (int) $matches[1] + 1 : 1; $ext = isset($matches[2]) ? $matches[2] : ''; return " (" . $index . ")" . $ext; } protected function upcount_name($name) { return preg_replace_callback("/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/", array($this, "upcount_name_callback"), $name, 1); } protected function get_unique_filename($file_path, $name, $size, $type, $error, $index, $content_range) { while (is_dir($this->get_upload_path($name))) { $name = $this->upcount_name($name); } $uploaded_bytes = $this->fix_integer_overflow((int) @$content_range[1]); while (is_file($this->get_upload_path($name))) { if ($uploaded_bytes === $this->get_file_size($this->get_upload_path($name))) { break; } $name = $this->upcount_name($name); } return $name; } protected function get_valid_image_extensions($file_path) { switch ($this->imagetype($file_path)) { case self::IMAGETYPE_JPEG: return array("jpg", "jpeg"); case self::IMAGETYPE_PNG: return array("png"); case self::IMAGETYPE_GIF: return array("gif"); } } protected function fix_file_extension($file_path, $name, $size, $type, $error, $index, $content_range) { if (strpos($name, ".") === false && preg_match("/^image\/(gif|jpe?g|png)/", $type, $matches)) { $name .= "." . $matches[1]; } if ($this->options["correct_image_extensions"]) { $extensions = $this->get_valid_image_extensions($file_path); if (!empty($extensions)) { $parts = explode(".", $name); $extIndex = count($parts) - 1; $ext = strtolower(@$parts[$extIndex]); if (!in_array($ext, $extensions)) { $parts[$extIndex] = $extensions[0]; $name = implode(".", $parts); } } } return $name; } protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range) { $name = trim($this->basename(stripslashes($name)), ".\x0.. "); $replacement = $this->options["replace_dots_in_filenames"]; if (!empty($replacement)) { $parts = explode(".", $name); if (count($parts) > 2) { $ext = array_pop($parts); $name = implode($replacement, $parts) . "." . $ext; } } if (!$name) { $name = str_replace(".", "-", microtime(true)); } return $name; } protected function get_file_name($file_path, $name, $size, $type, $error, $index, $content_range) { $name = $this->trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range); return $this->get_unique_filename($file_path, $this->fix_file_extension($file_path, $name, $size, $type, $error, $index, $content_range), $size, $type, $error, $index, $content_range); } protected function get_scaled_image_file_paths($file_name, $version) { $file_path = $this->get_upload_path($file_name); if (!empty($version)) { $version_dir = $this->get_upload_path(null, $version); if (!is_dir($version_dir)) { mkdir($version_dir, $this->options["mkdir_mode"], true); } $new_file_path = $version_dir . "/" . $file_name; } else { $new_file_path = $file_path; } return array($file_path, $new_file_path); } protected function gd_get_image_object($file_path, $func, $no_cache = false) { if (empty($this->image_objects[$file_path]) || $no_cache) { $this->gd_destroy_image_object($file_path); $this->image_objects[$file_path] = $func($file_path); } return $this->image_objects[$file_path]; } protected function gd_set_image_object($file_path, $image) { $this->gd_destroy_image_object($file_path); $this->image_objects[$file_path] = $image; } protected function gd_destroy_image_object($file_path) { $image = isset($this->image_objects[$file_path]) ? $this->image_objects[$file_path] : null; return $image && imagedestroy($image); } protected function gd_imageflip($image, $mode) { if (function_exists("imageflip")) { return imageflip($image, $mode); } $new_width = $src_width = imagesx($image); $new_height = $src_height = imagesy($image); $new_img = imagecreatetruecolor($new_width, $new_height); $src_x = 0; $src_y = 0; switch ($mode) { case "1": $src_y = $new_height - 1; $src_height = -$new_height; break; case "2": $src_x = $new_width - 1; $src_width = -$new_width; break; case "3": $src_y = $new_height - 1; $src_height = -$new_height; $src_x = $new_width - 1; $src_width = -$new_width; break; default: return $image; } imagecopyresampled($new_img, $image, 0, 0, $src_x, $src_y, $new_width, $new_height, $src_width, $src_height); return $new_img; } protected function gd_orient_image($file_path, $src_img) { if (!function_exists("exif_read_data")) { return false; } $exif = @exif_read_data($file_path); if ($exif === false) { return false; } $orientation = (int) @$exif["Orientation"]; if ($orientation < 2 || $orientation > 8) { return false; } switch ($orientation) { case 2: $new_img = $this->gd_imageflip($src_img, defined("IMG_FLIP_VERTICAL") ? IMG_FLIP_VERTICAL : 2); break; case 3: $new_img = imagerotate($src_img, 180, 0); break; case 4: $new_img = $this->gd_imageflip($src_img, defined("IMG_FLIP_HORIZONTAL") ? IMG_FLIP_HORIZONTAL : 1); break; case 5: $tmp_img = $this->gd_imageflip($src_img, defined("IMG_FLIP_HORIZONTAL") ? IMG_FLIP_HORIZONTAL : 1); $new_img = imagerotate($tmp_img, 270, 0); imagedestroy($tmp_img); break; case 6: $new_img = imagerotate($src_img, 270, 0); break; case 7: $tmp_img = $this->gd_imageflip($src_img, defined("IMG_FLIP_VERTICAL") ? IMG_FLIP_VERTICAL : 2); $new_img = imagerotate($tmp_img, 270, 0); imagedestroy($tmp_img); break; case 8: $new_img = imagerotate($src_img, 90, 0); break; default: return false; } $this->gd_set_image_object($file_path, $new_img); return true; } protected function gd_create_scaled_image($file_name, $version, $options) { if (!function_exists("imagecreatetruecolor")) { error_log("Function not found: imagecreatetruecolor"); return false; } list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name, $version); $type = strtolower(substr(strrchr($file_name, "."), 1)); switch ($type) { case "jpg": case "jpeg": $src_func = "imagecreatefromjpeg"; $write_func = "imagejpeg"; $image_quality = isset($options["jpeg_quality"]) ? $options["jpeg_quality"] : 75; break; case "gif": $src_func = "imagecreatefromgif"; $write_func = "imagegif"; $image_quality = null; break; case "png": $src_func = "imagecreatefrompng"; $write_func = "imagepng"; $image_quality = isset($options["png_quality"]) ? $options["png_quality"] : 9; break; default: return false; } $src_img = $this->gd_get_image_object($file_path, $src_func, !empty($options["no_cache"])); $image_oriented = false; if (!empty($options["auto_orient"]) && $this->gd_orient_image($file_path, $src_img)) { $image_oriented = true; $src_img = $this->gd_get_image_object($file_path, $src_func); } $max_width = $img_width = imagesx($src_img); $max_height = $img_height = imagesy($src_img); if (!empty($options["max_width"])) { $max_width = $options["max_width"]; } if (!empty($options["max_height"])) { $max_height = $options["max_height"]; } $scale = min($max_width / $img_width, $max_height / $img_height); if ($scale >= 1) { if ($image_oriented) { return $write_func($src_img, $new_file_path, $image_quality); } if ($file_path !== $new_file_path) { return copy($file_path, $new_file_path); } return true; } if (empty($options["crop"])) { $new_width = $img_width * $scale; $new_height = $img_height * $scale; $dst_x = 0; $dst_y = 0; $new_img = imagecreatetruecolor($new_width, $new_height); } else { if ($img_width / $img_height >= $max_width / $max_height) { $new_width = $img_width / ($img_height / $max_height); $new_height = $max_height; } else { $new_width = $max_width; $new_height = $img_height / ($img_width / $max_width); } $dst_x = 0 - ($new_width - $max_width) / 2; $dst_y = 0 - ($new_height - $max_height) / 2; $new_img = imagecreatetruecolor($max_width, $max_height); } switch ($type) { case "gif": imagecolortransparent($new_img, imagecolorallocate($new_img, 0, 0, 0)); break; case "png": imagecolortransparent($new_img, imagecolorallocate($new_img, 0, 0, 0)); imagealphablending($new_img, false); imagesavealpha($new_img, true); break; } $success = imagecopyresampled($new_img, $src_img, $dst_x, $dst_y, 0, 0, $new_width, $new_height, $img_width, $img_height) && $write_func($new_img, $new_file_path, $image_quality); $this->gd_set_image_object($file_path, $new_img); return $success; } protected function imagick_get_image_object($file_path, $no_cache = false) { if (empty($this->image_objects[$file_path]) || $no_cache) { $this->imagick_destroy_image_object($file_path); $image = new \Imagick(); if (!empty($this->options["imagick_resource_limits"])) { foreach ($this->options["imagick_resource_limits"] as $type => $limit) { $image->setResourceLimit($type, $limit); } } try { $image->readImage($file_path); } catch (ImagickException $e) { error_log($e->getMessage()); return null; } $this->image_objects[$file_path] = $image; } return $this->image_objects[$file_path]; } protected function imagick_set_image_object($file_path, $image) { $this->imagick_destroy_image_object($file_path); $this->image_objects[$file_path] = $image; } protected function imagick_destroy_image_object($file_path) { $image = isset($this->image_objects[$file_path]) ? $this->image_objects[$file_path] : null; return $image && $image->destroy(); } protected function imagick_orient_image($image) { $orientation = $image->getImageOrientation(); $background = new \ImagickPixel("none"); switch ($orientation) { case \imagick::ORIENTATION_TOPRIGHT: $image->flopImage(); break; case \imagick::ORIENTATION_BOTTOMRIGHT: $image->rotateImage($background, 180); break; case \imagick::ORIENTATION_BOTTOMLEFT: $image->flipImage(); break; case \imagick::ORIENTATION_LEFTTOP: $image->flopImage(); $image->rotateImage($background, 270); break; case \imagick::ORIENTATION_RIGHTTOP: $image->rotateImage($background, 90); break; case \imagick::ORIENTATION_RIGHTBOTTOM: $image->flipImage(); $image->rotateImage($background, 270); break; case \imagick::ORIENTATION_LEFTBOTTOM: $image->rotateImage($background, 270); break; default: return false; } $image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT); return true; } protected function imagick_create_scaled_image($file_name, $version, $options) { list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name, $version); $image = $this->imagick_get_image_object($file_path, !empty($options["crop"]) || !empty($options["no_cache"])); if (is_null($image)) { return false; } if ($image->getImageFormat() === "GIF") { $images = $image->coalesceImages(); foreach ($images as $frame) { $image = $frame; $this->imagick_set_image_object($file_name, $image); break; } } $image_oriented = false; if (!empty($options["auto_orient"])) { $image_oriented = $this->imagick_orient_image($image); } $image_resize = false; $new_width = $max_width = $img_width = $image->getImageWidth(); $new_height = $max_height = $img_height = $image->getImageHeight(); if (isset($options["max_width"])) { $image_resize = true; $new_width = $max_width = $options["max_width"]; } if (isset($options["max_height"])) { $image_resize = true; $new_height = $max_height = $options["max_height"]; } $image_strip = isset($options["strip"]) ? $options["strip"] : false; if (!$image_oriented && $max_width >= $img_width && $max_height >= $img_height && !$image_strip && empty($options["jpeg_quality"])) { if ($file_path !== $new_file_path) { return copy($file_path, $new_file_path); } return true; } $crop = isset($options["crop"]) ? $options["crop"] : false; if ($crop) { $x = 0; $y = 0; if ($img_width / $img_height >= $max_width / $max_height) { $new_width = 0; $x = ($img_width / ($img_height / $max_height) - $max_width) / 2; } else { $new_height = 0; $y = ($img_height / ($img_width / $max_width) - $max_height) / 2; } } $success = $image->resizeImage($new_width, $new_height, isset($options["filter"]) ? $options["filter"] : \imagick::FILTER_LANCZOS, isset($options["blur"]) ? $options["blur"] : 1, $new_width && $new_height); if ($success && $crop) { $success = $image->cropImage($max_width, $max_height, $x, $y); if ($success) { $success = $image->setImagePage($max_width, $max_height, 0, 0); } } $type = strtolower(substr(strrchr($file_name, "."), 1)); switch ($type) { case "jpg": case "jpeg": if (!empty($options["jpeg_quality"])) { $image->setImageCompression(\imagick::COMPRESSION_JPEG); $image->setImageCompressionQuality($options["jpeg_quality"]); } break; } if ($image_strip) { $image->stripImage(); } return $success && $image->writeImage($new_file_path); } protected function imagemagick_create_scaled_image($file_name, $version, $options) { list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name, $version); $resize = @$options["max_width"] . (empty($options["max_height"]) ? '' : "X" . $options["max_height"]); if (!$resize && empty($options["auto_orient"])) { if ($file_path !== $new_file_path) { return copy($file_path, $new_file_path); } return true; } $cmd = $this->options["convert_bin"]; if (!empty($this->options["convert_params"])) { $cmd .= " " . $this->options["convert_params"]; } $cmd .= " " . escapeshellarg($file_path); if (!empty($options["auto_orient"])) { $cmd .= " -auto-orient"; } if ($resize) { $cmd .= " -coalesce"; if (empty($options["crop"])) { $cmd .= " -resize " . escapeshellarg($resize . ">"); } else { $cmd .= " -resize " . escapeshellarg($resize . "^"); $cmd .= " -gravity center"; $cmd .= " -crop " . escapeshellarg($resize . "+0+0"); } $cmd .= " +repage"; } if (!empty($options["convert_params"])) { $cmd .= " " . $options["convert_params"]; } $cmd .= " " . escapeshellarg($new_file_path); exec($cmd, $output, $error); if ($error) { error_log(implode("\n", $output)); return false; } return true; } protected function get_image_size($file_path) { if ($this->options["image_library"]) { if (extension_loaded("imagick")) { $image = new \Imagick(); try { if (@$image->pingImage($file_path)) { $dimensions = array($image->getImageWidth(), $image->getImageHeight()); $image->destroy(); return $dimensions; } return false; } catch (\Exception $e) { error_log($e->getMessage()); } } if ($this->options["image_library"] === 2) { $cmd = $this->options["identify_bin"]; $cmd .= " -ping " . escapeshellarg($file_path); exec($cmd, $output, $error); if (!$error && !empty($output)) { $infos = preg_split("/\s+/", substr($output[0], strlen($file_path))); $dimensions = preg_split("/x/", $infos[2]); return $dimensions; } return false; } } if (!function_exists("getimagesize")) { error_log("Function not found: getimagesize"); return false; } return @getimagesize($file_path); } protected function create_scaled_image($file_name, $version, $options) { try { if ($this->options["image_library"] === 2) { return $this->imagemagick_create_scaled_image($file_name, $version, $options); } if ($this->options["image_library"] && extension_loaded("imagick")) { return $this->imagick_create_scaled_image($file_name, $version, $options); } return $this->gd_create_scaled_image($file_name, $version, $options); } catch (\Exception $e) { error_log($e->getMessage()); return false; } } protected function destroy_image_object($file_path) { if ($this->options["image_library"] && extension_loaded("imagick")) { return $this->imagick_destroy_image_object($file_path); } } protected function imagetype($file_path) { $fp = fopen($file_path, "r"); $data = fread($fp, 4); fclose($fp); if ($data === "GIF8") { return self::IMAGETYPE_GIF; } if (bin2hex(substr($data, 0, 3)) === "ffd8ff") { return self::IMAGETYPE_JPEG; } if (bin2hex(@$data[0]) . substr($data, 1, 4) === "89PNG") { return self::IMAGETYPE_PNG; } return false; } protected function is_valid_image_file($file_path) { return !!$this->imagetype($file_path); } protected function has_image_file_extension($file_path) { return !!preg_match("/\.(gif|jpe?g|png)$/i", $file_path); } protected function handle_image_file($file_path, $file) { $failed_versions = array(); foreach ($this->options["image_versions"] as $version => $options) { if ($this->create_scaled_image($file->name, $version, $options)) { if (!empty($version)) { $file->{$version . "Url"} = $this->get_download_url($file->name, $version); } else { $file->size = $this->get_file_size($file_path, true); } } else { $failed_versions[] = $version ? $version : "original"; } } if (count($failed_versions)) { $file->error = $this->get_error_message("image_resize") . " (" . implode(", ", $failed_versions) . ")"; } $this->destroy_image_object($file_path); } protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = new \stdClass(); $file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error, $index, $content_range); $file->size = $this->fix_integer_overflow((int) $size); $file->type = $type; if ($this->validate($uploaded_file, $file, $error, $index, $content_range)) { $this->handle_form_data($file, $index); $upload_dir = $this->get_upload_path(); if (!is_dir($upload_dir)) { mkdir($upload_dir, $this->options["mkdir_mode"], true); } $file_path = $this->get_upload_path($file->name); $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path); if ($uploaded_file && is_uploaded_file($uploaded_file)) { if ($append_file) { file_put_contents($file_path, fopen($uploaded_file, "r"), FILE_APPEND); } else { move_uploaded_file($uploaded_file, $file_path); } } else { file_put_contents($file_path, fopen($this->options["input_stream"], "r"), $append_file ? FILE_APPEND : 0); } $file_size = $this->get_file_size($file_path, $append_file); if ($file_size === $file->size) { $file->url = $this->get_download_url($file->name); if ($this->has_image_file_extension($file->name)) { if ($content_range && !$this->validate_image_file($file_path, $file, $error, $index)) { unlink($file_path); } else { $this->handle_image_file($file_path, $file); } } } else { $file->size = $file_size; if (!$content_range && $this->options["discard_aborted_uploads"]) { unlink($file_path); $file->error = $this->get_error_message("abort"); } } $this->set_additional_file_properties($file); } return $file; } protected function readfile($file_path) { $file_size = $this->get_file_size($file_path); $chunk_size = $this->options["readfile_chunk_size"]; if ($chunk_size && $file_size > $chunk_size) { $handle = fopen($file_path, "rb"); while (!feof($handle)) { echo fread($handle, $chunk_size); @ob_flush(); @flush(); } fclose($handle); return $file_size; } return readfile($file_path); } protected function body($str) { echo $str; } protected function header($str) { header($str); } protected function get_upload_data($id) { return @$_FILES[$id]; } protected function get_post_param($id) { return @$_POST[$id]; } protected function get_query_param($id) { return @$_GET[$id]; } protected function get_server_var($id) { return @$_SERVER[$id]; } protected function handle_form_data($file, $index) { } protected function get_version_param() { return $this->basename(stripslashes($this->get_query_param("version"))); } protected function get_singular_param_name() { return substr($this->options["param_name"], 0, -1); } protected function get_file_name_param() { $name = $this->get_singular_param_name(); return $this->basename(stripslashes($this->get_query_param($name))); } protected function get_file_names_params() { $params = $this->get_query_param($this->options["param_name"]); if (!$params) { return null; } foreach ($params as $key => $value) { $params[$key] = $this->basename(stripslashes($value)); } return $params; } protected function get_file_type($file_path) { switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) { case "jpeg": case "jpg": return self::IMAGETYPE_JPEG; case "png": return self::IMAGETYPE_PNG; case "gif": return self::IMAGETYPE_GIF; default: return ''; } } protected function download() { switch ($this->options["download_via_php"]) { case 1: $redirect_header = null; break; case 2: $redirect_header = "X-Sendfile"; break; case 3: $redirect_header = "X-Accel-Redirect"; break; default: return $this->header("HTTP/1.1 403 Forbidden"); } $file_name = $this->get_file_name_param(); if (!$this->is_valid_file_object($file_name)) { return $this->header("HTTP/1.1 404 Not Found"); } if ($redirect_header) { return $this->header($redirect_header . ": " . $this->get_download_url($file_name, $this->get_version_param(), true)); } $file_path = $this->get_upload_path($file_name, $this->get_version_param()); $this->header("X-Content-Type-Options: nosniff"); if (!preg_match($this->options["inline_file_types"], $file_name)) { $this->header("Content-Type: application/octet-stream"); $this->header("Content-Disposition: attachment; filename="" . $file_name . """); } else { $this->header("Content-Type: " . $this->get_file_type($file_path)); $this->header("Content-Disposition: inline; filename="" . $file_name . """); } $this->header("Content-Length: " . $this->get_file_size($file_path)); $this->header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($file_path))); $this->readfile($file_path); } protected function send_content_type_header() { $this->header("Vary: Accept"); if (strpos($this->get_server_var("HTTP_ACCEPT"), "application/json") !== false) { $this->header("Content-type: application/json"); } else { $this->header("Content-type: text/plain"); } } protected function send_access_control_headers() { $this->header("Access-Control-Allow-Origin: " . $this->options["access_control_allow_origin"]); $this->header("Access-Control-Allow-Credentials: " . ($this->options["access_control_allow_credentials"] ? "true" : "false")); $this->header("Access-Control-Allow-Methods: " . implode(", ", $this->options["access_control_allow_methods"])); $this->header("Access-Control-Allow-Headers: " . implode(", ", $this->options["access_control_allow_headers"])); } public function generate_response($content, $print_response = true) { $this->response = $content; if ($print_response) { $json = json_encode($content); $redirect = stripslashes($this->get_post_param("redirect")); if ($redirect && preg_match($this->options["redirect_allow_target"], $redirect)) { return $this->header("Location: " . sprintf($redirect, rawurlencode($json))); } $this->head(); if ($this->get_server_var("HTTP_CONTENT_RANGE")) { $files = isset($content[$this->options["param_name"]]) ? $content[$this->options["param_name"]] : null; if ($files && is_array($files) && is_object($files[0]) && $files[0]->size) { $this->header("Range: 0-" . ($this->fix_integer_overflow((int) $files[0]->size) - 1)); } } $this->body($json); } return $content; } public function get_response() { return $this->response; } public function head() { $this->header("Pragma: no-cache"); $this->header("Cache-Control: no-store, no-cache, must-revalidate"); $this->header("Content-Disposition: inline; filename="files.json""); $this->header("X-Content-Type-Options: nosniff"); if ($this->options["access_control_allow_origin"]) { $this->send_access_control_headers(); } $this->send_content_type_header(); } public function get($print_response = true) { if ($print_response && $this->get_query_param("download")) { return $this->download(); } $file_name = $this->get_file_name_param(); if ($file_name) { $response = array($this->get_singular_param_name() => $this->get_file_object($file_name)); } else { $response = array($this->options["param_name"] => $this->get_file_objects()); } return $this->generate_response($response, $print_response); } public function post($print_response = true) { if ($this->get_query_param("_method") === "DELETE") { return $this->delete($print_response); } $upload = $this->get_upload_data($this->options["param_name"]); $content_disposition_header = $this->get_server_var("HTTP_CONTENT_DISPOSITION"); $file_name = $content_disposition_header ? rawurldecode(preg_replace("/(^[^"]+")|("$)/", '', $content_disposition_header)) : null; $content_range_header = $this->get_server_var("HTTP_CONTENT_RANGE"); $content_range = $content_range_header ? preg_split("/[^0-9]+/", $content_range_header) : null; $size = @$content_range[3]; $files = array(); if ($upload) { if (is_array($upload["tmp_name"])) { foreach ($upload["tmp_name"] as $index => $value) { $files[] = $this->handle_file_upload($upload["tmp_name"][$index], $file_name ? $file_name : $upload["name"][$index], $size ? $size : $upload["size"][$index], $upload["type"][$index], $upload["error"][$index], $index, $content_range); } } else { $files[] = $this->handle_file_upload(isset($upload["tmp_name"]) ? $upload["tmp_name"] : null, $file_name ? $file_name : (isset($upload["name"]) ? $upload["name"] : null), $size ? $size : (isset($upload["size"]) ? $upload["size"] : $this->get_server_var("CONTENT_LENGTH")), isset($upload["type"]) ? $upload["type"] : $this->get_server_var("CONTENT_TYPE"), isset($upload["error"]) ? $upload["error"] : null, null, $content_range); } } $response = array($this->options["param_name"] => $files); return $this->generate_response($response, $print_response); } public function delete($print_response = true) { $file_names = $this->get_file_names_params(); if (empty($file_names)) { $file_names = array($this->get_file_name_param()); } $response = array(); foreach ($file_names as $file_name) { $file_path = $this->get_upload_path($file_name); $success = strlen($file_name) > 0 && $file_name[0] !== "." && is_file($file_path) && unlink($file_path); if ($success) { foreach ($this->options["image_versions"] as $version => $options) { if (!empty($version)) { $file = $this->get_upload_path($file_name, $version); if (is_file($file)) { unlink($file); } } } } $response[$file_name] = $success; } return $this->generate_response($response, $print_response); } protected function basename($filepath, $suffix = null) { $splited = preg_split("/\//", rtrim($filepath, "/ ")); return substr(basename("X" . $splited[count($splited) - 1], $suffix), 1); } } ?>

Did this file decode correctly?

Original Code

<?php
 class UploadHandler { protected $options; protected $error_messages = array(1 => "\x54\150\145\40\165\160\x6c\x6f\x61\144\x65\x64\40\x66\x69\x6c\145\x20\145\x78\x63\145\145\x64\163\x20\164\150\x65\40\x75\160\154\157\x61\x64\x5f\x6d\141\170\x5f\x66\151\x6c\x65\x73\151\172\145\x20\144\151\162\x65\x63\x74\x69\166\x65\40\x69\156\x20\x70\150\x70\x2e\x69\x6e\x69", 2 => "\x54\x68\145\40\165\160\154\x6f\141\144\145\x64\x20\x66\x69\x6c\x65\40\x65\x78\143\x65\x65\144\163\x20\x74\150\145\40\x4d\101\130\137\106\x49\x4c\x45\137\123\x49\x5a\x45\40\144\151\x72\x65\x63\164\x69\166\x65\40\x74\x68\x61\164\x20\167\x61\163\x20\163\160\145\143\151\x66\151\145\144\x20\x69\156\x20\x74\150\x65\40\x48\124\115\114\x20\x66\157\x72\155", 3 => "\124\x68\x65\x20\x75\x70\154\x6f\x61\x64\145\144\x20\146\151\154\x65\x20\167\141\163\x20\x6f\x6e\x6c\171\x20\x70\x61\162\164\151\141\154\154\x79\40\x75\160\154\157\141\144\145\144", 4 => "\x4e\157\40\x66\x69\x6c\145\x20\167\x61\163\40\x75\160\x6c\x6f\x61\144\145\144", 6 => "\115\x69\x73\163\x69\156\x67\x20\141\40\x74\145\x6d\160\x6f\162\141\x72\x79\40\x66\157\154\144\145\x72", 7 => "\106\x61\x69\x6c\x65\144\x20\164\x6f\40\x77\x72\x69\164\x65\x20\146\x69\x6c\x65\x20\164\x6f\40\x64\151\x73\x6b", 8 => "\x41\x20\120\x48\x50\40\145\170\164\x65\x6e\x73\151\157\x6e\x20\x73\x74\x6f\160\x70\x65\144\40\x74\150\x65\40\x66\151\x6c\x65\40\165\x70\154\x6f\141\x64", "\160\x6f\163\x74\137\x6d\141\x78\137\x73\x69\x7a\145" => "\124\x68\x65\x20\165\x70\154\x6f\141\144\145\x64\x20\146\x69\154\x65\x20\x65\x78\x63\145\x65\144\163\x20\164\150\145\40\x70\x6f\163\x74\137\x6d\x61\170\x5f\163\x69\172\x65\40\x64\151\x72\145\143\x74\x69\x76\x65\x20\x69\x6e\40\x70\x68\160\56\x69\x6e\x69", "\155\141\170\137\146\151\154\x65\137\163\151\x7a\x65" => "\106\151\x6c\145\x20\x69\x73\x20\164\157\x6f\x20\142\151\x67", "\x6d\x69\156\x5f\146\151\154\x65\137\x73\x69\x7a\x65" => "\x46\x69\154\x65\x20\151\163\x20\x74\157\157\x20\163\x6d\141\x6c\x6c", "\141\143\143\145\x70\x74\x5f\x66\151\x6c\x65\x5f\164\x79\x70\145\163" => "\x46\x69\x6c\145\x74\x79\x70\x65\40\x6e\x6f\164\40\141\x6c\x6c\157\167\145\x64", "\x6d\x61\x78\x5f\156\165\x6d\142\x65\x72\x5f\157\146\137\146\151\154\145\x73" => "\x4d\141\170\x69\x6d\x75\155\x20\x6e\165\x6d\x62\145\162\40\x6f\x66\40\x66\151\154\145\x73\40\145\x78\143\145\x65\144\145\x64", "\151\156\166\141\154\x69\144\137\146\151\x6c\145\x5f\164\x79\x70\145" => "\x49\156\x76\141\154\x69\x64\x20\146\151\154\145\40\x74\171\x70\145", "\155\x61\x78\x5f\167\x69\x64\164\150" => "\111\155\x61\x67\145\x20\145\x78\143\145\x65\144\163\40\155\x61\170\x69\155\x75\x6d\40\167\x69\x64\x74\x68", "\x6d\151\156\137\167\151\x64\164\150" => "\x49\x6d\x61\x67\x65\x20\162\x65\161\x75\x69\x72\x65\163\x20\x61\40\155\151\x6e\151\155\165\155\x20\x77\x69\144\x74\x68", "\x6d\x61\170\137\150\x65\151\147\x68\164" => "\x49\155\141\147\x65\x20\x65\170\x63\x65\145\144\x73\x20\x6d\x61\x78\x69\155\165\155\x20\150\x65\x69\147\x68\164", "\x6d\151\156\x5f\150\145\151\x67\150\164" => "\111\155\141\147\x65\40\162\x65\161\165\151\x72\145\x73\x20\x61\40\155\151\x6e\151\x6d\x75\x6d\40\x68\145\x69\147\x68\x74", "\x61\x62\x6f\162\164" => "\x46\x69\154\x65\40\165\160\x6c\x6f\x61\x64\x20\x61\142\157\162\x74\145\x64", "\151\x6d\141\147\x65\137\x72\x65\x73\151\x7a\145" => "\x46\141\x69\154\x65\x64\40\x74\x6f\x20\162\145\x73\151\x7a\145\x20\151\x6d\141\x67\x65"); const IMAGETYPE_GIF = "\x69\x6d\141\x67\x65\x2f\147\151\146"; const IMAGETYPE_JPEG = "\x69\155\x61\147\145\57\152\160\145\x67"; const IMAGETYPE_PNG = "\x69\x6d\x61\147\145\57\160\x6e\x67"; protected $image_objects = array(); protected $response = array(); public function __construct($options = null, $initialize = true, $error_messages = null) { $this->options = array("\x73\x63\162\x69\160\x74\x5f\x75\x72\154" => $this->get_full_url() . "\57" . $this->basename($this->get_server_var("\x53\103\x52\x49\x50\124\x5f\116\101\115\x45")), "\x75\160\x6c\x6f\141\144\x5f\x64\151\162" => dirname($this->get_server_var("\123\103\122\x49\x50\x54\x5f\x46\x49\x4c\x45\x4e\101\x4d\105")) . "\x2f\146\x69\154\145\163\57", "\x75\x70\154\157\141\x64\137\165\162\154" => $this->get_full_url() . "\x2f\x66\x69\154\x65\x73\x2f", "\151\x6e\x70\165\164\137\x73\x74\x72\x65\x61\155" => "\x70\150\160\72\x2f\57\x69\x6e\x70\165\164", "\165\x73\145\x72\x5f\144\151\162\163" => false, "\155\153\x64\151\x72\137\x6d\157\x64\145" => 493, "\160\141\x72\x61\155\137\x6e\x61\x6d\145" => "\x66\151\x6c\x65\x73", "\144\145\154\x65\164\145\x5f\164\x79\160\145" => "\x44\x45\114\105\x54\x45", "\141\x63\x63\145\x73\163\137\x63\x6f\156\164\162\x6f\x6c\137\141\x6c\x6c\x6f\x77\137\x6f\x72\151\x67\x69\x6e" => "\x2a", "\141\143\143\145\163\163\137\143\157\156\164\x72\157\154\x5f\x61\154\x6c\157\167\x5f\x63\x72\x65\x64\x65\x6e\164\x69\141\154\x73" => false, "\x61\x63\143\x65\163\163\x5f\143\x6f\x6e\164\162\x6f\154\x5f\x61\x6c\x6c\x6f\167\137\x6d\145\164\150\x6f\x64\163" => array("\x4f\120\124\x49\x4f\116\x53", "\x48\105\x41\104", "\107\x45\124", "\120\117\123\x54", "\120\125\x54", "\120\101\x54\x43\110", "\104\x45\x4c\105\x54\x45"), "\x61\x63\x63\145\163\163\x5f\143\x6f\x6e\x74\162\x6f\154\x5f\x61\154\154\157\167\x5f\150\x65\x61\x64\145\x72\x73" => array("\x43\x6f\x6e\164\x65\156\x74\55\x54\171\x70\145", "\103\157\156\x74\x65\156\x74\x2d\x52\141\x6e\147\x65", "\103\157\x6e\x74\145\x6e\x74\x2d\104\151\x73\x70\x6f\x73\151\164\151\157\x6e"), "\x72\x65\144\151\x72\145\143\x74\137\141\x6c\154\157\167\x5f\x74\141\162\147\145\x74" => "\57\x5e" . preg_quote(parse_url($this->get_server_var("\110\124\124\120\137\x52\105\x46\105\x52\105\122"), PHP_URL_SCHEME) . "\x3a\x2f\57" . parse_url($this->get_server_var("\x48\x54\x54\120\137\x52\105\106\x45\122\x45\122"), PHP_URL_HOST) . "\57", "\57") . "\57", "\x64\x6f\x77\156\154\x6f\141\x64\x5f\166\151\x61\x5f\160\x68\160" => false, "\x72\x65\x61\144\x66\151\x6c\145\x5f\143\x68\x75\x6e\153\x5f\163\x69\x7a\x65" => 10 * 1024 * 1024, "\x69\156\154\151\156\x65\137\146\x69\x6c\x65\137\164\x79\x70\145\163" => "\57\x5c\56\x28\147\151\x66\x7c\x6a\x70\145\77\x67\x7c\x70\156\147\51\44\57\x69", "\141\143\143\145\160\x74\x5f\x66\151\x6c\x65\137\x74\171\x70\x65\163" => "\57\x5c\x2e\x28\x67\151\146\x7c\152\x70\x65\77\147\x7c\x70\x6e\147\x29\44\x2f\x69", "\x72\x65\x70\154\x61\x63\x65\x5f\144\157\x74\x73\x5f\x69\156\137\146\x69\154\x65\x6e\141\x6d\145\x73" => "\55", "\155\141\x78\137\146\151\x6c\145\x5f\163\x69\172\x65" => null, "\155\151\156\x5f\x66\151\154\x65\x5f\163\151\172\x65" => 1, "\x6d\x61\x78\137\x6e\165\155\142\145\162\x5f\157\146\137\146\x69\x6c\x65\x73" => null, "\143\157\x72\162\145\x63\164\x5f\x69\x6d\x61\x67\x65\x5f\x65\x78\164\145\156\163\x69\x6f\x6e\163" => false, "\x6d\141\x78\x5f\x77\x69\144\164\x68" => null, "\x6d\x61\x78\137\150\145\151\147\x68\x74" => null, "\155\151\156\137\167\x69\144\164\150" => 1, "\155\x69\156\137\150\x65\151\x67\x68\x74" => 1, "\144\151\163\x63\x61\x72\x64\x5f\x61\x62\157\x72\164\145\144\137\165\x70\154\x6f\x61\x64\163" => true, "\x69\x6d\x61\147\145\137\154\151\142\x72\x61\x72\x79" => 1, "\x63\x6f\156\x76\x65\162\164\x5f\x62\151\x6e" => "\x63\x6f\156\x76\x65\x72\x74", "\x69\144\x65\x6e\164\x69\x66\171\137\x62\151\x6e" => "\151\144\x65\156\x74\x69\x66\x79", "\151\x6d\x61\147\145\137\166\145\x72\x73\x69\157\156\x73" => array('' => array("\x61\x75\x74\x6f\x5f\157\x72\x69\145\156\x74" => true), "\x74\150\x75\x6d\x62\x6e\x61\x69\154" => array("\155\141\x78\137\167\151\144\x74\x68" => 80, "\155\141\x78\137\150\x65\151\x67\150\164" => 80)), "\x70\162\151\x6e\164\137\162\x65\x73\160\x6f\x6e\x73\145" => true); if ($options) { $this->options = $options + $this->options; } if ($error_messages) { $this->error_messages = $error_messages + $this->error_messages; } if ($initialize) { $this->initialize(); } } protected function initialize() { switch ($this->get_server_var("\122\105\121\x55\x45\123\x54\x5f\115\105\x54\110\117\104")) { case "\117\120\x54\x49\117\x4e\x53": case "\110\105\101\x44": $this->head(); break; case "\107\x45\x54": $this->get($this->options["\x70\x72\151\156\x74\x5f\x72\145\163\x70\x6f\156\163\x65"]); break; case "\x50\101\124\103\110": case "\120\125\x54": case "\120\x4f\123\124": $this->post($this->options["\160\x72\x69\156\x74\x5f\x72\145\x73\x70\x6f\156\163\x65"]); break; case "\x44\105\x4c\x45\124\105": $this->delete($this->options["\160\162\x69\x6e\164\137\x72\145\163\x70\x6f\x6e\163\145"]); break; default: $this->header("\x48\x54\124\120\57\x31\x2e\x31\x20\64\x30\65\x20\x4d\145\164\150\157\144\40\116\157\164\40\x41\x6c\x6c\157\x77\x65\144"); } } protected function get_full_url() { $https = !empty($_SERVER["\x48\x54\x54\120\123"]) && strcasecmp($_SERVER["\110\x54\124\120\x53"], "\x6f\156") === 0 || !empty($_SERVER["\x48\x54\x54\120\x5f\130\x5f\x46\117\x52\x57\101\x52\104\x45\x44\137\120\122\x4f\124\x4f"]) && strcasecmp($_SERVER["\110\124\124\x50\137\130\137\x46\x4f\122\x57\101\122\x44\105\x44\x5f\120\122\x4f\124\x4f"], "\150\164\164\x70\x73") === 0; return ($https ? "\150\164\164\160\x73\x3a\x2f\x2f" : "\x68\x74\164\x70\72\57\x2f") . (!empty($_SERVER["\x52\x45\x4d\x4f\x54\x45\137\x55\123\105\122"]) ? $_SERVER["\x52\x45\x4d\x4f\124\105\x5f\x55\123\105\x52"] . "\x40" : '') . (isset($_SERVER["\x48\124\124\120\x5f\110\x4f\x53\x54"]) ? $_SERVER["\x48\x54\124\x50\x5f\x48\117\x53\124"] : $_SERVER["\123\x45\x52\126\105\x52\x5f\x4e\101\115\x45"] . ($https && $_SERVER["\x53\x45\122\x56\x45\x52\x5f\x50\117\x52\x54"] === 443 || $_SERVER["\x53\x45\122\126\105\122\137\x50\117\122\124"] === 80 ? '' : "\72" . $_SERVER["\123\105\122\x56\105\122\x5f\x50\x4f\122\124"])) . substr($_SERVER["\123\x43\122\111\120\124\137\x4e\x41\x4d\105"], 0, strrpos($_SERVER["\x53\x43\122\x49\120\x54\x5f\x4e\101\x4d\105"], "\57")); } protected function get_user_id() { @session_start(); return session_id(); } protected function get_user_path() { if ($this->options["\x75\x73\145\x72\x5f\x64\151\162\163"]) { return $this->get_user_id() . "\x2f"; } return ''; } protected function get_upload_path($file_name = null, $version = null) { $file_name = $file_name ? $file_name : ''; if (empty($version)) { $version_path = ''; } else { $version_dir = @$this->options["\x69\x6d\141\x67\145\137\166\145\162\x73\151\x6f\x6e\163"][$version]["\x75\x70\x6c\157\141\144\137\x64\151\x72"]; if ($version_dir) { return $version_dir . $this->get_user_path() . $file_name; } $version_path = $version . "\x2f"; } return $this->options["\165\x70\x6c\x6f\141\x64\x5f\144\x69\162"] . $this->get_user_path() . $version_path . $file_name; } protected function get_query_separator($url) { return strpos($url, "\77") === false ? "\x3f" : "\x26"; } protected function get_download_url($file_name, $version = null, $direct = false) { if (!$direct && $this->options["\x64\157\167\x6e\x6c\x6f\141\144\137\x76\x69\141\137\160\150\160"]) { $url = $this->options["\163\143\162\151\x70\164\x5f\165\x72\154"] . $this->get_query_separator($this->options["\x73\x63\x72\x69\160\164\137\x75\x72\x6c"]) . $this->get_singular_param_name() . "\x3d" . rawurlencode($file_name); if ($version) { $url .= "\46\x76\145\162\163\151\157\156\75" . rawurlencode($version); } return $url . "\x26\144\157\167\x6e\x6c\x6f\x61\x64\x3d\61"; } if (empty($version)) { $version_path = ''; } else { $version_url = @$this->options["\x69\x6d\141\x67\145\137\166\145\x72\163\x69\157\156\x73"][$version]["\x75\x70\x6c\x6f\x61\x64\137\165\162\154"]; if ($version_url) { return $version_url . $this->get_user_path() . rawurlencode($file_name); } $version_path = rawurlencode($version) . "\x2f"; } return $this->options["\165\160\x6c\157\x61\144\x5f\x75\x72\154"] . $this->get_user_path() . $version_path . rawurlencode($file_name); } protected function set_additional_file_properties($file) { $file->deleteUrl = $this->options["\x73\143\162\x69\x70\164\137\165\x72\154"] . $this->get_query_separator($this->options["\163\x63\162\151\160\x74\x5f\165\x72\x6c"]) . $this->get_singular_param_name() . "\x3d" . rawurlencode($file->name); $file->deleteType = $this->options["\x64\x65\x6c\145\x74\145\137\164\171\x70\145"]; if ($file->deleteType !== "\x44\x45\x4c\x45\124\105") { $file->deleteUrl .= "\46\137\155\x65\164\150\157\144\x3d\104\x45\x4c\x45\x54\x45"; } if ($this->options["\141\143\143\x65\x73\x73\137\x63\157\156\164\162\157\154\x5f\141\154\x6c\x6f\x77\137\143\x72\145\x64\x65\156\x74\151\141\x6c\163"]) { $file->deleteWithCredentials = true; } } protected function fix_integer_overflow($size) { if ($size < 0) { $size += 2.0 * (PHP_INT_MAX + 1); } return $size; } protected function get_file_size($file_path, $clear_stat_cache = false) { if ($clear_stat_cache) { if (version_compare(PHP_VERSION, "\65\56\63\x2e\x30") >= 0) { clearstatcache(true, $file_path); } else { clearstatcache(); } } return $this->fix_integer_overflow(filesize($file_path)); } protected function is_valid_file_object($file_name) { $file_path = $this->get_upload_path($file_name); if (strlen($file_name) > 0 && $file_name[0] !== "\56" && is_file($file_path)) { return true; } return false; } protected function get_file_object($file_name) { if ($this->is_valid_file_object($file_name)) { $file = new \stdClass(); $file->name = $file_name; $file->size = $this->get_file_size($this->get_upload_path($file_name)); $file->url = $this->get_download_url($file->name); foreach ($this->options["\x69\x6d\x61\x67\x65\x5f\166\x65\x72\x73\x69\x6f\156\x73"] as $version => $options) { if (!empty($version)) { if (is_file($this->get_upload_path($file_name, $version))) { $file->{$version . "\125\162\x6c"} = $this->get_download_url($file->name, $version); } } } $this->set_additional_file_properties($file); return $file; } return null; } protected function get_file_objects($iteration_method = "\x67\145\164\137\x66\151\154\x65\137\x6f\142\152\x65\143\x74") { $upload_dir = $this->get_upload_path(); if (!is_dir($upload_dir)) { return array(); } return array_values(array_filter(array_map(array($this, $iteration_method), scandir($upload_dir)))); } protected function count_file_objects() { return count($this->get_file_objects("\151\x73\x5f\166\x61\154\x69\144\x5f\146\x69\x6c\x65\137\157\142\x6a\145\143\164")); } protected function get_error_message($error) { return isset($this->error_messages[$error]) ? $this->error_messages[$error] : $error; } public function get_config_bytes($val) { $val = trim($val); $last = strtolower($val[strlen($val) - 1]); if (is_numeric($val)) { $val = (int) $val; } else { $val = (int) substr($val, 0, -1); } switch ($last) { case "\147": $val *= 1024; case "\x6d": $val *= 1024; case "\x6b": $val *= 1024; } return $this->fix_integer_overflow($val); } protected function validate_image_file($uploaded_file, $file, $error, $index) { if ($this->imagetype($uploaded_file) !== $this->get_file_type($file->name)) { $file->error = $this->get_error_message("\x69\x6e\x76\141\154\151\x64\x5f\x66\151\154\x65\137\164\x79\160\x65"); return false; } $max_width = @$this->options["\155\141\x78\137\x77\x69\x64\164\150"]; $max_height = @$this->options["\155\x61\x78\137\150\145\x69\147\150\x74"]; $min_width = @$this->options["\155\x69\156\x5f\x77\x69\144\164\x68"]; $min_height = @$this->options["\x6d\151\x6e\137\x68\x65\151\x67\150\x74"]; if ($max_width || $max_height || $min_width || $min_height) { list($img_width, $img_height) = $this->get_image_size($uploaded_file); if (@$this->options["\151\x6d\141\147\x65\137\166\x65\162\x73\x69\157\156\x73"]['']["\x61\x75\x74\157\137\x6f\162\151\145\156\x74"] && function_exists("\x65\x78\x69\146\x5f\x72\145\x61\x64\x5f\144\141\x74\x61") && ($exif = @exif_read_data($uploaded_file)) && (int) @$exif["\x4f\x72\151\145\x6e\x74\x61\x74\151\157\x6e"] >= 5) { $tmp = $img_width; $img_width = $img_height; $img_height = $tmp; unset($tmp); } if (!empty($img_width) && !empty($img_height)) { if ($max_width && $img_width > $max_width) { $file->error = $this->get_error_message("\x6d\x61\x78\137\167\151\x64\x74\150"); return false; } if ($max_height && $img_height > $max_height) { $file->error = $this->get_error_message("\155\x61\170\137\150\x65\151\147\x68\164"); return false; } if ($min_width && $img_width < $min_width) { $file->error = $this->get_error_message("\155\151\x6e\x5f\167\151\x64\x74\150"); return false; } if ($min_height && $img_height < $min_height) { $file->error = $this->get_error_message("\155\x69\x6e\137\x68\x65\151\147\150\x74"); return false; } } } return true; } protected function validate($uploaded_file, $file, $error, $index, $content_range) { if ($error) { $file->error = $this->get_error_message($error); return false; } $content_length = $this->fix_integer_overflow((int) $this->get_server_var("\x43\x4f\116\x54\105\x4e\x54\x5f\114\105\x4e\107\124\x48")); $post_max_size = $this->get_config_bytes(ini_get("\x70\157\x73\164\137\x6d\x61\x78\137\x73\x69\x7a\145")); if ($post_max_size && $content_length > $post_max_size) { $file->error = $this->get_error_message("\160\157\x73\164\137\x6d\141\170\137\163\x69\x7a\x65"); return false; } if (!preg_match($this->options["\x61\143\143\145\x70\x74\x5f\146\151\x6c\145\137\x74\171\160\145\163"], $file->name)) { $file->error = $this->get_error_message("\141\143\x63\x65\x70\164\x5f\146\x69\x6c\x65\137\x74\x79\160\145\x73"); return false; } if ($uploaded_file && is_uploaded_file($uploaded_file)) { $file_size = $this->get_file_size($uploaded_file); } else { $file_size = $content_length; } if ($this->options["\155\141\x78\x5f\146\151\x6c\145\x5f\x73\x69\172\x65"] && ($file_size > $this->options["\155\x61\x78\x5f\x66\x69\154\145\x5f\x73\151\x7a\145"] || $file->size > $this->options["\x6d\141\170\x5f\146\151\154\145\x5f\x73\x69\x7a\145"])) { $file->error = $this->get_error_message("\x6d\141\x78\137\x66\151\154\145\137\x73\x69\x7a\145"); return false; } if ($this->options["\155\151\x6e\x5f\x66\151\154\x65\137\163\151\172\145"] && $file_size < $this->options["\x6d\151\x6e\137\x66\151\154\x65\137\163\x69\172\145"]) { $file->error = $this->get_error_message("\155\x69\x6e\x5f\x66\151\154\x65\137\163\x69\172\145"); return false; } if (is_int($this->options["\x6d\x61\x78\137\156\x75\x6d\142\x65\162\x5f\157\x66\137\146\x69\x6c\145\x73"]) && $this->count_file_objects() >= $this->options["\155\141\170\x5f\x6e\x75\x6d\x62\x65\162\x5f\157\146\x5f\146\x69\154\x65\x73"] && !is_file($this->get_upload_path($file->name))) { $file->error = $this->get_error_message("\x6d\141\x78\x5f\x6e\x75\x6d\x62\145\162\137\x6f\146\137\146\151\x6c\145\163"); return false; } if (!$content_range && $this->has_image_file_extension($file->name)) { return $this->validate_image_file($uploaded_file, $file, $error, $index); } return true; } protected function upcount_name_callback($matches) { $index = isset($matches[1]) ? (int) $matches[1] + 1 : 1; $ext = isset($matches[2]) ? $matches[2] : ''; return "\40\50" . $index . "\51" . $ext; } protected function upcount_name($name) { return preg_replace_callback("\57\x28\x3f\72\50\77\x3a\x20\x5c\50\x28\x5b\134\144\135\x2b\51\134\x29\x29\77\50\x5c\x2e\x5b\x5e\x2e\x5d\x2b\x29\x29\77\44\x2f", array($this, "\165\160\x63\157\165\x6e\164\x5f\156\x61\x6d\145\x5f\143\141\154\x6c\142\141\143\153"), $name, 1); } protected function get_unique_filename($file_path, $name, $size, $type, $error, $index, $content_range) { while (is_dir($this->get_upload_path($name))) { $name = $this->upcount_name($name); } $uploaded_bytes = $this->fix_integer_overflow((int) @$content_range[1]); while (is_file($this->get_upload_path($name))) { if ($uploaded_bytes === $this->get_file_size($this->get_upload_path($name))) { break; } $name = $this->upcount_name($name); } return $name; } protected function get_valid_image_extensions($file_path) { switch ($this->imagetype($file_path)) { case self::IMAGETYPE_JPEG: return array("\x6a\x70\x67", "\x6a\160\145\147"); case self::IMAGETYPE_PNG: return array("\160\x6e\147"); case self::IMAGETYPE_GIF: return array("\x67\151\146"); } } protected function fix_file_extension($file_path, $name, $size, $type, $error, $index, $content_range) { if (strpos($name, "\x2e") === false && preg_match("\x2f\136\151\155\141\147\x65\x5c\x2f\x28\147\151\x66\x7c\152\x70\x65\77\x67\x7c\160\x6e\147\51\x2f", $type, $matches)) { $name .= "\56" . $matches[1]; } if ($this->options["\x63\157\162\162\x65\x63\x74\x5f\151\x6d\x61\x67\x65\x5f\145\x78\x74\x65\x6e\x73\x69\x6f\x6e\x73"]) { $extensions = $this->get_valid_image_extensions($file_path); if (!empty($extensions)) { $parts = explode("\x2e", $name); $extIndex = count($parts) - 1; $ext = strtolower(@$parts[$extIndex]); if (!in_array($ext, $extensions)) { $parts[$extIndex] = $extensions[0]; $name = implode("\x2e", $parts); } } } return $name; } protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range) { $name = trim($this->basename(stripslashes($name)), "\56\x0\56\56\x20"); $replacement = $this->options["\162\145\160\154\141\143\x65\x5f\144\x6f\x74\163\x5f\151\x6e\137\x66\x69\154\145\x6e\141\155\145\163"]; if (!empty($replacement)) { $parts = explode("\56", $name); if (count($parts) > 2) { $ext = array_pop($parts); $name = implode($replacement, $parts) . "\x2e" . $ext; } } if (!$name) { $name = str_replace("\x2e", "\55", microtime(true)); } return $name; } protected function get_file_name($file_path, $name, $size, $type, $error, $index, $content_range) { $name = $this->trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range); return $this->get_unique_filename($file_path, $this->fix_file_extension($file_path, $name, $size, $type, $error, $index, $content_range), $size, $type, $error, $index, $content_range); } protected function get_scaled_image_file_paths($file_name, $version) { $file_path = $this->get_upload_path($file_name); if (!empty($version)) { $version_dir = $this->get_upload_path(null, $version); if (!is_dir($version_dir)) { mkdir($version_dir, $this->options["\x6d\153\x64\151\162\137\155\x6f\144\145"], true); } $new_file_path = $version_dir . "\x2f" . $file_name; } else { $new_file_path = $file_path; } return array($file_path, $new_file_path); } protected function gd_get_image_object($file_path, $func, $no_cache = false) { if (empty($this->image_objects[$file_path]) || $no_cache) { $this->gd_destroy_image_object($file_path); $this->image_objects[$file_path] = $func($file_path); } return $this->image_objects[$file_path]; } protected function gd_set_image_object($file_path, $image) { $this->gd_destroy_image_object($file_path); $this->image_objects[$file_path] = $image; } protected function gd_destroy_image_object($file_path) { $image = isset($this->image_objects[$file_path]) ? $this->image_objects[$file_path] : null; return $image && imagedestroy($image); } protected function gd_imageflip($image, $mode) { if (function_exists("\x69\x6d\x61\147\x65\x66\154\x69\160")) { return imageflip($image, $mode); } $new_width = $src_width = imagesx($image); $new_height = $src_height = imagesy($image); $new_img = imagecreatetruecolor($new_width, $new_height); $src_x = 0; $src_y = 0; switch ($mode) { case "\61": $src_y = $new_height - 1; $src_height = -$new_height; break; case "\x32": $src_x = $new_width - 1; $src_width = -$new_width; break; case "\x33": $src_y = $new_height - 1; $src_height = -$new_height; $src_x = $new_width - 1; $src_width = -$new_width; break; default: return $image; } imagecopyresampled($new_img, $image, 0, 0, $src_x, $src_y, $new_width, $new_height, $src_width, $src_height); return $new_img; } protected function gd_orient_image($file_path, $src_img) { if (!function_exists("\145\170\151\146\x5f\x72\x65\141\x64\137\144\x61\164\x61")) { return false; } $exif = @exif_read_data($file_path); if ($exif === false) { return false; } $orientation = (int) @$exif["\117\162\151\145\x6e\164\141\164\x69\157\x6e"]; if ($orientation < 2 || $orientation > 8) { return false; } switch ($orientation) { case 2: $new_img = $this->gd_imageflip($src_img, defined("\111\x4d\107\137\x46\114\x49\120\137\x56\105\x52\124\111\103\x41\x4c") ? IMG_FLIP_VERTICAL : 2); break; case 3: $new_img = imagerotate($src_img, 180, 0); break; case 4: $new_img = $this->gd_imageflip($src_img, defined("\111\x4d\107\137\x46\114\x49\120\x5f\x48\117\122\111\132\x4f\116\124\x41\x4c") ? IMG_FLIP_HORIZONTAL : 1); break; case 5: $tmp_img = $this->gd_imageflip($src_img, defined("\x49\115\x47\137\106\x4c\111\x50\x5f\x48\117\x52\x49\132\117\x4e\124\x41\114") ? IMG_FLIP_HORIZONTAL : 1); $new_img = imagerotate($tmp_img, 270, 0); imagedestroy($tmp_img); break; case 6: $new_img = imagerotate($src_img, 270, 0); break; case 7: $tmp_img = $this->gd_imageflip($src_img, defined("\111\x4d\107\x5f\106\114\111\120\x5f\126\105\122\124\111\x43\x41\x4c") ? IMG_FLIP_VERTICAL : 2); $new_img = imagerotate($tmp_img, 270, 0); imagedestroy($tmp_img); break; case 8: $new_img = imagerotate($src_img, 90, 0); break; default: return false; } $this->gd_set_image_object($file_path, $new_img); return true; } protected function gd_create_scaled_image($file_name, $version, $options) { if (!function_exists("\x69\155\x61\147\x65\x63\162\x65\x61\x74\x65\164\x72\x75\x65\143\157\x6c\x6f\162")) { error_log("\106\165\156\x63\x74\151\157\x6e\x20\156\157\164\40\x66\157\165\x6e\x64\x3a\x20\x69\x6d\141\147\145\x63\x72\145\141\x74\x65\x74\x72\165\145\x63\x6f\x6c\157\x72"); return false; } list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name, $version); $type = strtolower(substr(strrchr($file_name, "\x2e"), 1)); switch ($type) { case "\152\x70\x67": case "\152\160\145\x67": $src_func = "\x69\155\x61\x67\145\143\162\x65\x61\164\x65\x66\162\x6f\155\x6a\160\x65\x67"; $write_func = "\x69\x6d\x61\x67\145\x6a\160\x65\x67"; $image_quality = isset($options["\x6a\160\x65\147\x5f\x71\165\x61\x6c\151\x74\x79"]) ? $options["\152\x70\145\x67\137\161\165\141\x6c\151\164\x79"] : 75; break; case "\x67\x69\x66": $src_func = "\151\x6d\x61\147\x65\x63\162\145\141\x74\x65\146\x72\x6f\x6d\x67\x69\146"; $write_func = "\151\155\x61\x67\x65\147\151\146"; $image_quality = null; break; case "\x70\x6e\x67": $src_func = "\x69\x6d\x61\x67\x65\143\x72\x65\x61\x74\145\146\x72\157\155\160\x6e\x67"; $write_func = "\151\x6d\x61\x67\145\x70\156\x67"; $image_quality = isset($options["\x70\156\147\x5f\x71\165\x61\x6c\151\164\171"]) ? $options["\x70\x6e\x67\137\161\x75\x61\x6c\x69\x74\x79"] : 9; break; default: return false; } $src_img = $this->gd_get_image_object($file_path, $src_func, !empty($options["\x6e\157\x5f\x63\141\143\150\145"])); $image_oriented = false; if (!empty($options["\141\x75\x74\x6f\137\x6f\162\151\x65\x6e\164"]) && $this->gd_orient_image($file_path, $src_img)) { $image_oriented = true; $src_img = $this->gd_get_image_object($file_path, $src_func); } $max_width = $img_width = imagesx($src_img); $max_height = $img_height = imagesy($src_img); if (!empty($options["\x6d\x61\x78\137\x77\151\144\164\150"])) { $max_width = $options["\x6d\141\170\x5f\167\x69\144\164\150"]; } if (!empty($options["\155\x61\x78\x5f\x68\x65\x69\147\x68\164"])) { $max_height = $options["\x6d\x61\170\x5f\x68\145\151\x67\x68\164"]; } $scale = min($max_width / $img_width, $max_height / $img_height); if ($scale >= 1) { if ($image_oriented) { return $write_func($src_img, $new_file_path, $image_quality); } if ($file_path !== $new_file_path) { return copy($file_path, $new_file_path); } return true; } if (empty($options["\x63\162\157\160"])) { $new_width = $img_width * $scale; $new_height = $img_height * $scale; $dst_x = 0; $dst_y = 0; $new_img = imagecreatetruecolor($new_width, $new_height); } else { if ($img_width / $img_height >= $max_width / $max_height) { $new_width = $img_width / ($img_height / $max_height); $new_height = $max_height; } else { $new_width = $max_width; $new_height = $img_height / ($img_width / $max_width); } $dst_x = 0 - ($new_width - $max_width) / 2; $dst_y = 0 - ($new_height - $max_height) / 2; $new_img = imagecreatetruecolor($max_width, $max_height); } switch ($type) { case "\x67\x69\x66": imagecolortransparent($new_img, imagecolorallocate($new_img, 0, 0, 0)); break; case "\x70\156\x67": imagecolortransparent($new_img, imagecolorallocate($new_img, 0, 0, 0)); imagealphablending($new_img, false); imagesavealpha($new_img, true); break; } $success = imagecopyresampled($new_img, $src_img, $dst_x, $dst_y, 0, 0, $new_width, $new_height, $img_width, $img_height) && $write_func($new_img, $new_file_path, $image_quality); $this->gd_set_image_object($file_path, $new_img); return $success; } protected function imagick_get_image_object($file_path, $no_cache = false) { if (empty($this->image_objects[$file_path]) || $no_cache) { $this->imagick_destroy_image_object($file_path); $image = new \Imagick(); if (!empty($this->options["\x69\155\141\x67\151\143\153\137\162\145\x73\x6f\165\x72\x63\x65\x5f\x6c\x69\x6d\151\x74\x73"])) { foreach ($this->options["\151\x6d\141\147\151\x63\x6b\x5f\162\145\163\157\x75\162\x63\x65\137\x6c\x69\x6d\151\x74\163"] as $type => $limit) { $image->setResourceLimit($type, $limit); } } try { $image->readImage($file_path); } catch (ImagickException $e) { error_log($e->getMessage()); return null; } $this->image_objects[$file_path] = $image; } return $this->image_objects[$file_path]; } protected function imagick_set_image_object($file_path, $image) { $this->imagick_destroy_image_object($file_path); $this->image_objects[$file_path] = $image; } protected function imagick_destroy_image_object($file_path) { $image = isset($this->image_objects[$file_path]) ? $this->image_objects[$file_path] : null; return $image && $image->destroy(); } protected function imagick_orient_image($image) { $orientation = $image->getImageOrientation(); $background = new \ImagickPixel("\x6e\157\x6e\x65"); switch ($orientation) { case \imagick::ORIENTATION_TOPRIGHT: $image->flopImage(); break; case \imagick::ORIENTATION_BOTTOMRIGHT: $image->rotateImage($background, 180); break; case \imagick::ORIENTATION_BOTTOMLEFT: $image->flipImage(); break; case \imagick::ORIENTATION_LEFTTOP: $image->flopImage(); $image->rotateImage($background, 270); break; case \imagick::ORIENTATION_RIGHTTOP: $image->rotateImage($background, 90); break; case \imagick::ORIENTATION_RIGHTBOTTOM: $image->flipImage(); $image->rotateImage($background, 270); break; case \imagick::ORIENTATION_LEFTBOTTOM: $image->rotateImage($background, 270); break; default: return false; } $image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT); return true; } protected function imagick_create_scaled_image($file_name, $version, $options) { list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name, $version); $image = $this->imagick_get_image_object($file_path, !empty($options["\x63\x72\157\160"]) || !empty($options["\156\x6f\x5f\143\x61\143\x68\145"])); if (is_null($image)) { return false; } if ($image->getImageFormat() === "\x47\x49\x46") { $images = $image->coalesceImages(); foreach ($images as $frame) { $image = $frame; $this->imagick_set_image_object($file_name, $image); break; } } $image_oriented = false; if (!empty($options["\x61\165\164\157\137\x6f\x72\x69\x65\156\x74"])) { $image_oriented = $this->imagick_orient_image($image); } $image_resize = false; $new_width = $max_width = $img_width = $image->getImageWidth(); $new_height = $max_height = $img_height = $image->getImageHeight(); if (isset($options["\x6d\141\x78\137\x77\151\144\164\x68"])) { $image_resize = true; $new_width = $max_width = $options["\155\141\170\137\167\x69\x64\x74\150"]; } if (isset($options["\155\141\170\137\150\x65\151\147\150\x74"])) { $image_resize = true; $new_height = $max_height = $options["\155\x61\x78\x5f\150\x65\x69\147\150\x74"]; } $image_strip = isset($options["\163\x74\x72\x69\160"]) ? $options["\163\164\162\x69\x70"] : false; if (!$image_oriented && $max_width >= $img_width && $max_height >= $img_height && !$image_strip && empty($options["\x6a\x70\x65\147\x5f\x71\165\141\154\151\164\171"])) { if ($file_path !== $new_file_path) { return copy($file_path, $new_file_path); } return true; } $crop = isset($options["\x63\162\x6f\160"]) ? $options["\x63\x72\x6f\160"] : false; if ($crop) { $x = 0; $y = 0; if ($img_width / $img_height >= $max_width / $max_height) { $new_width = 0; $x = ($img_width / ($img_height / $max_height) - $max_width) / 2; } else { $new_height = 0; $y = ($img_height / ($img_width / $max_width) - $max_height) / 2; } } $success = $image->resizeImage($new_width, $new_height, isset($options["\x66\151\x6c\x74\x65\x72"]) ? $options["\146\151\x6c\x74\x65\x72"] : \imagick::FILTER_LANCZOS, isset($options["\x62\x6c\165\162"]) ? $options["\142\x6c\165\x72"] : 1, $new_width && $new_height); if ($success && $crop) { $success = $image->cropImage($max_width, $max_height, $x, $y); if ($success) { $success = $image->setImagePage($max_width, $max_height, 0, 0); } } $type = strtolower(substr(strrchr($file_name, "\x2e"), 1)); switch ($type) { case "\152\x70\147": case "\152\160\x65\x67": if (!empty($options["\x6a\160\x65\147\x5f\161\x75\141\154\x69\x74\171"])) { $image->setImageCompression(\imagick::COMPRESSION_JPEG); $image->setImageCompressionQuality($options["\x6a\160\x65\147\x5f\161\x75\141\154\x69\x74\x79"]); } break; } if ($image_strip) { $image->stripImage(); } return $success && $image->writeImage($new_file_path); } protected function imagemagick_create_scaled_image($file_name, $version, $options) { list($file_path, $new_file_path) = $this->get_scaled_image_file_paths($file_name, $version); $resize = @$options["\x6d\x61\170\137\167\151\x64\x74\x68"] . (empty($options["\155\x61\x78\x5f\150\x65\151\147\x68\x74"]) ? '' : "\130" . $options["\x6d\x61\170\x5f\150\x65\151\x67\x68\x74"]); if (!$resize && empty($options["\141\165\164\157\137\157\x72\151\x65\156\x74"])) { if ($file_path !== $new_file_path) { return copy($file_path, $new_file_path); } return true; } $cmd = $this->options["\x63\157\156\x76\145\162\164\137\142\x69\156"]; if (!empty($this->options["\143\x6f\x6e\x76\x65\162\x74\x5f\160\x61\x72\x61\155\163"])) { $cmd .= "\x20" . $this->options["\x63\x6f\156\x76\145\x72\164\137\x70\141\162\141\x6d\163"]; } $cmd .= "\x20" . escapeshellarg($file_path); if (!empty($options["\x61\x75\x74\x6f\137\157\162\151\145\156\x74"])) { $cmd .= "\x20\55\141\x75\164\157\x2d\157\x72\151\145\156\x74"; } if ($resize) { $cmd .= "\x20\55\x63\x6f\141\x6c\x65\x73\x63\145"; if (empty($options["\x63\x72\x6f\x70"])) { $cmd .= "\40\x2d\x72\x65\x73\151\x7a\x65\40" . escapeshellarg($resize . "\x3e"); } else { $cmd .= "\40\55\162\x65\163\151\172\145\40" . escapeshellarg($resize . "\x5e"); $cmd .= "\40\x2d\x67\162\141\x76\151\164\171\40\143\x65\x6e\x74\x65\x72"; $cmd .= "\40\55\x63\162\157\160\x20" . escapeshellarg($resize . "\53\x30\53\60"); } $cmd .= "\x20\53\x72\x65\x70\141\x67\145"; } if (!empty($options["\x63\x6f\156\x76\x65\x72\164\x5f\160\141\162\x61\x6d\163"])) { $cmd .= "\x20" . $options["\143\157\156\x76\145\162\x74\x5f\160\x61\x72\141\x6d\163"]; } $cmd .= "\x20" . escapeshellarg($new_file_path); exec($cmd, $output, $error); if ($error) { error_log(implode("\x5c\156", $output)); return false; } return true; } protected function get_image_size($file_path) { if ($this->options["\x69\155\141\147\x65\x5f\x6c\x69\142\x72\141\162\x79"]) { if (extension_loaded("\151\x6d\141\147\151\143\153")) { $image = new \Imagick(); try { if (@$image->pingImage($file_path)) { $dimensions = array($image->getImageWidth(), $image->getImageHeight()); $image->destroy(); return $dimensions; } return false; } catch (\Exception $e) { error_log($e->getMessage()); } } if ($this->options["\x69\x6d\141\147\145\x5f\x6c\x69\142\162\x61\162\x79"] === 2) { $cmd = $this->options["\151\x64\x65\x6e\x74\151\146\x79\x5f\x62\x69\156"]; $cmd .= "\x20\x2d\x70\151\x6e\147\40" . escapeshellarg($file_path); exec($cmd, $output, $error); if (!$error && !empty($output)) { $infos = preg_split("\57\134\x73\x2b\x2f", substr($output[0], strlen($file_path))); $dimensions = preg_split("\x2f\x78\57", $infos[2]); return $dimensions; } return false; } } if (!function_exists("\147\145\x74\151\155\141\147\x65\x73\151\172\x65")) { error_log("\x46\x75\x6e\x63\x74\151\157\156\40\x6e\x6f\x74\x20\x66\x6f\165\156\144\72\x20\x67\145\164\x69\x6d\x61\x67\x65\x73\x69\x7a\x65"); return false; } return @getimagesize($file_path); } protected function create_scaled_image($file_name, $version, $options) { try { if ($this->options["\151\x6d\x61\147\x65\137\x6c\151\142\162\141\x72\x79"] === 2) { return $this->imagemagick_create_scaled_image($file_name, $version, $options); } if ($this->options["\x69\x6d\141\x67\x65\137\154\151\142\x72\141\x72\171"] && extension_loaded("\x69\155\x61\147\x69\x63\153")) { return $this->imagick_create_scaled_image($file_name, $version, $options); } return $this->gd_create_scaled_image($file_name, $version, $options); } catch (\Exception $e) { error_log($e->getMessage()); return false; } } protected function destroy_image_object($file_path) { if ($this->options["\151\x6d\x61\147\x65\137\154\151\x62\x72\x61\x72\171"] && extension_loaded("\151\155\x61\x67\151\x63\x6b")) { return $this->imagick_destroy_image_object($file_path); } } protected function imagetype($file_path) { $fp = fopen($file_path, "\x72"); $data = fread($fp, 4); fclose($fp); if ($data === "\x47\x49\x46\70") { return self::IMAGETYPE_GIF; } if (bin2hex(substr($data, 0, 3)) === "\146\x66\x64\70\146\x66") { return self::IMAGETYPE_JPEG; } if (bin2hex(@$data[0]) . substr($data, 1, 4) === "\70\x39\120\116\x47") { return self::IMAGETYPE_PNG; } return false; } protected function is_valid_image_file($file_path) { return !!$this->imagetype($file_path); } protected function has_image_file_extension($file_path) { return !!preg_match("\57\134\56\50\x67\x69\146\174\152\160\145\77\x67\174\x70\156\147\x29\x24\x2f\x69", $file_path); } protected function handle_image_file($file_path, $file) { $failed_versions = array(); foreach ($this->options["\x69\x6d\141\147\x65\137\x76\x65\162\x73\151\x6f\156\163"] as $version => $options) { if ($this->create_scaled_image($file->name, $version, $options)) { if (!empty($version)) { $file->{$version . "\125\x72\x6c"} = $this->get_download_url($file->name, $version); } else { $file->size = $this->get_file_size($file_path, true); } } else { $failed_versions[] = $version ? $version : "\157\x72\151\147\x69\x6e\141\154"; } } if (count($failed_versions)) { $file->error = $this->get_error_message("\x69\x6d\141\x67\145\137\x72\145\x73\151\172\145") . "\x20\x28" . implode("\54\x20", $failed_versions) . "\51"; } $this->destroy_image_object($file_path); } protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = new \stdClass(); $file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error, $index, $content_range); $file->size = $this->fix_integer_overflow((int) $size); $file->type = $type; if ($this->validate($uploaded_file, $file, $error, $index, $content_range)) { $this->handle_form_data($file, $index); $upload_dir = $this->get_upload_path(); if (!is_dir($upload_dir)) { mkdir($upload_dir, $this->options["\x6d\x6b\x64\x69\162\x5f\155\157\x64\x65"], true); } $file_path = $this->get_upload_path($file->name); $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path); if ($uploaded_file && is_uploaded_file($uploaded_file)) { if ($append_file) { file_put_contents($file_path, fopen($uploaded_file, "\x72"), FILE_APPEND); } else { move_uploaded_file($uploaded_file, $file_path); } } else { file_put_contents($file_path, fopen($this->options["\151\x6e\x70\165\x74\x5f\163\164\162\x65\141\x6d"], "\x72"), $append_file ? FILE_APPEND : 0); } $file_size = $this->get_file_size($file_path, $append_file); if ($file_size === $file->size) { $file->url = $this->get_download_url($file->name); if ($this->has_image_file_extension($file->name)) { if ($content_range && !$this->validate_image_file($file_path, $file, $error, $index)) { unlink($file_path); } else { $this->handle_image_file($file_path, $file); } } } else { $file->size = $file_size; if (!$content_range && $this->options["\144\151\x73\143\141\x72\144\137\x61\x62\x6f\162\164\145\144\137\165\x70\154\157\141\x64\163"]) { unlink($file_path); $file->error = $this->get_error_message("\x61\x62\157\x72\x74"); } } $this->set_additional_file_properties($file); } return $file; } protected function readfile($file_path) { $file_size = $this->get_file_size($file_path); $chunk_size = $this->options["\162\145\x61\x64\146\151\154\145\x5f\x63\150\x75\x6e\x6b\137\163\x69\x7a\x65"]; if ($chunk_size && $file_size > $chunk_size) { $handle = fopen($file_path, "\x72\x62"); while (!feof($handle)) { echo fread($handle, $chunk_size); @ob_flush(); @flush(); } fclose($handle); return $file_size; } return readfile($file_path); } protected function body($str) { echo $str; } protected function header($str) { header($str); } protected function get_upload_data($id) { return @$_FILES[$id]; } protected function get_post_param($id) { return @$_POST[$id]; } protected function get_query_param($id) { return @$_GET[$id]; } protected function get_server_var($id) { return @$_SERVER[$id]; } protected function handle_form_data($file, $index) { } protected function get_version_param() { return $this->basename(stripslashes($this->get_query_param("\166\145\x72\x73\151\157\x6e"))); } protected function get_singular_param_name() { return substr($this->options["\160\141\x72\141\155\137\x6e\141\x6d\145"], 0, -1); } protected function get_file_name_param() { $name = $this->get_singular_param_name(); return $this->basename(stripslashes($this->get_query_param($name))); } protected function get_file_names_params() { $params = $this->get_query_param($this->options["\x70\x61\162\141\155\137\156\141\155\x65"]); if (!$params) { return null; } foreach ($params as $key => $value) { $params[$key] = $this->basename(stripslashes($value)); } return $params; } protected function get_file_type($file_path) { switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) { case "\x6a\x70\x65\147": case "\152\160\x67": return self::IMAGETYPE_JPEG; case "\160\x6e\x67": return self::IMAGETYPE_PNG; case "\x67\151\146": return self::IMAGETYPE_GIF; default: return ''; } } protected function download() { switch ($this->options["\144\157\x77\156\x6c\157\x61\x64\137\166\x69\141\137\160\150\x70"]) { case 1: $redirect_header = null; break; case 2: $redirect_header = "\x58\x2d\x53\x65\x6e\x64\x66\x69\x6c\x65"; break; case 3: $redirect_header = "\x58\x2d\101\x63\x63\145\x6c\x2d\x52\145\x64\x69\162\145\143\x74"; break; default: return $this->header("\x48\x54\124\120\x2f\x31\56\61\x20\x34\60\63\x20\106\x6f\x72\142\x69\x64\144\145\x6e"); } $file_name = $this->get_file_name_param(); if (!$this->is_valid_file_object($file_name)) { return $this->header("\x48\x54\124\x50\x2f\x31\x2e\61\40\64\x30\64\40\116\x6f\164\40\x46\157\165\x6e\x64"); } if ($redirect_header) { return $this->header($redirect_header . "\72\40" . $this->get_download_url($file_name, $this->get_version_param(), true)); } $file_path = $this->get_upload_path($file_name, $this->get_version_param()); $this->header("\130\55\103\x6f\156\164\145\x6e\164\x2d\124\x79\x70\145\55\117\160\164\x69\157\x6e\x73\72\40\x6e\x6f\163\x6e\x69\x66\x66"); if (!preg_match($this->options["\x69\x6e\154\x69\156\x65\137\x66\x69\x6c\145\137\164\171\x70\145\163"], $file_name)) { $this->header("\x43\157\x6e\x74\x65\156\164\55\x54\x79\x70\145\72\40\141\160\160\x6c\151\143\141\x74\151\x6f\x6e\x2f\x6f\143\164\x65\164\55\163\x74\x72\x65\141\155"); $this->header("\x43\x6f\x6e\164\145\x6e\x74\55\104\151\x73\160\x6f\x73\x69\164\151\157\156\x3a\x20\x61\x74\164\141\143\x68\155\145\x6e\x74\73\40\146\151\154\x65\x6e\141\155\145\x3d\42" . $file_name . "\x22"); } else { $this->header("\103\x6f\x6e\164\x65\156\164\x2d\124\x79\x70\x65\72\40" . $this->get_file_type($file_path)); $this->header("\x43\x6f\x6e\x74\145\156\x74\55\104\151\x73\x70\157\163\x69\x74\151\157\156\x3a\40\x69\x6e\154\x69\x6e\x65\x3b\40\146\151\154\x65\156\x61\155\145\x3d\x22" . $file_name . "\42"); } $this->header("\x43\x6f\156\164\x65\156\164\55\x4c\x65\156\147\x74\150\x3a\40" . $this->get_file_size($file_path)); $this->header("\x4c\x61\x73\x74\x2d\x4d\x6f\x64\151\146\x69\145\x64\72\x20" . gmdate("\104\54\x20\144\40\115\x20\131\40\x48\x3a\x69\x3a\163\40\124", filemtime($file_path))); $this->readfile($file_path); } protected function send_content_type_header() { $this->header("\126\x61\162\x79\72\40\x41\143\143\x65\160\164"); if (strpos($this->get_server_var("\x48\x54\x54\x50\x5f\101\103\103\105\120\124"), "\141\x70\x70\x6c\151\143\141\x74\x69\157\156\57\152\163\157\x6e") !== false) { $this->header("\103\157\x6e\x74\145\156\x74\55\164\x79\x70\145\x3a\x20\x61\x70\x70\154\x69\143\141\164\151\x6f\x6e\x2f\152\x73\157\x6e"); } else { $this->header("\103\x6f\x6e\164\145\x6e\x74\x2d\x74\171\x70\x65\72\40\164\x65\x78\x74\x2f\160\154\141\x69\156"); } } protected function send_access_control_headers() { $this->header("\101\143\x63\145\x73\x73\55\x43\157\156\x74\x72\x6f\x6c\55\x41\154\x6c\157\x77\x2d\x4f\162\x69\147\151\156\72\40" . $this->options["\x61\143\143\145\x73\163\x5f\x63\157\x6e\x74\162\157\154\137\141\154\x6c\x6f\167\137\x6f\162\x69\147\151\156"]); $this->header("\x41\143\x63\x65\163\x73\55\x43\x6f\x6e\x74\162\x6f\x6c\x2d\101\x6c\x6c\x6f\167\x2d\103\x72\x65\144\145\156\164\x69\x61\x6c\163\x3a\40" . ($this->options["\x61\x63\143\x65\163\163\137\143\x6f\156\164\x72\157\x6c\137\x61\154\x6c\157\167\x5f\143\162\x65\x64\x65\156\x74\x69\x61\154\x73"] ? "\164\x72\165\145" : "\146\x61\x6c\163\145")); $this->header("\101\143\x63\x65\x73\163\55\x43\x6f\156\164\x72\157\154\55\101\154\x6c\x6f\167\x2d\x4d\145\x74\150\x6f\144\x73\72\x20" . implode("\x2c\40", $this->options["\x61\x63\x63\145\x73\x73\x5f\143\x6f\156\164\162\x6f\154\137\141\154\154\x6f\x77\137\155\x65\164\150\x6f\144\163"])); $this->header("\101\143\x63\145\163\163\x2d\103\157\x6e\x74\162\x6f\154\x2d\x41\154\x6c\157\x77\x2d\110\x65\x61\x64\145\x72\x73\x3a\40" . implode("\x2c\40", $this->options["\141\x63\x63\x65\163\x73\137\143\157\156\164\x72\157\x6c\137\x61\154\154\x6f\x77\x5f\x68\145\141\x64\145\x72\163"])); } public function generate_response($content, $print_response = true) { $this->response = $content; if ($print_response) { $json = json_encode($content); $redirect = stripslashes($this->get_post_param("\162\145\x64\151\x72\145\x63\164")); if ($redirect && preg_match($this->options["\162\145\x64\x69\x72\145\x63\164\x5f\141\154\154\x6f\x77\x5f\x74\141\x72\147\x65\164"], $redirect)) { return $this->header("\x4c\x6f\143\x61\x74\151\157\x6e\72\40" . sprintf($redirect, rawurlencode($json))); } $this->head(); if ($this->get_server_var("\x48\x54\124\120\137\103\117\116\x54\105\x4e\x54\x5f\122\x41\116\x47\x45")) { $files = isset($content[$this->options["\x70\x61\162\141\155\x5f\x6e\141\155\145"]]) ? $content[$this->options["\160\141\162\141\x6d\137\x6e\141\155\x65"]] : null; if ($files && is_array($files) && is_object($files[0]) && $files[0]->size) { $this->header("\x52\x61\156\x67\x65\x3a\x20\x30\55" . ($this->fix_integer_overflow((int) $files[0]->size) - 1)); } } $this->body($json); } return $content; } public function get_response() { return $this->response; } public function head() { $this->header("\x50\162\141\147\155\141\x3a\40\156\x6f\x2d\143\141\143\x68\145"); $this->header("\x43\141\143\x68\145\x2d\103\x6f\156\x74\x72\x6f\x6c\72\40\x6e\157\x2d\163\x74\x6f\162\x65\54\x20\156\x6f\x2d\143\x61\x63\150\145\x2c\40\155\x75\x73\x74\55\x72\145\166\x61\x6c\151\x64\x61\x74\145"); $this->header("\103\x6f\156\x74\145\x6e\164\x2d\104\151\x73\160\157\163\151\x74\x69\x6f\156\x3a\40\151\156\x6c\151\156\145\73\40\x66\x69\154\x65\x6e\141\155\145\75\42\146\x69\x6c\x65\x73\56\152\163\157\156\x22"); $this->header("\130\55\x43\157\156\x74\145\156\164\x2d\x54\171\x70\x65\55\117\x70\164\x69\157\x6e\163\72\x20\156\157\163\x6e\x69\x66\146"); if ($this->options["\141\x63\x63\x65\163\x73\137\x63\157\156\x74\x72\157\154\137\141\154\x6c\157\x77\137\157\162\x69\147\151\x6e"]) { $this->send_access_control_headers(); } $this->send_content_type_header(); } public function get($print_response = true) { if ($print_response && $this->get_query_param("\x64\x6f\167\156\154\x6f\141\x64")) { return $this->download(); } $file_name = $this->get_file_name_param(); if ($file_name) { $response = array($this->get_singular_param_name() => $this->get_file_object($file_name)); } else { $response = array($this->options["\x70\141\162\141\155\137\156\x61\x6d\145"] => $this->get_file_objects()); } return $this->generate_response($response, $print_response); } public function post($print_response = true) { if ($this->get_query_param("\137\155\145\x74\x68\x6f\144") === "\x44\x45\x4c\105\x54\x45") { return $this->delete($print_response); } $upload = $this->get_upload_data($this->options["\x70\141\162\x61\155\x5f\x6e\x61\x6d\x65"]); $content_disposition_header = $this->get_server_var("\x48\124\124\120\x5f\103\117\x4e\124\105\x4e\x54\137\104\x49\x53\120\117\123\111\124\x49\117\116"); $file_name = $content_disposition_header ? rawurldecode(preg_replace("\57\x28\x5e\x5b\136\x22\135\x2b\42\x29\174\50\42\44\x29\57", '', $content_disposition_header)) : null; $content_range_header = $this->get_server_var("\110\124\124\x50\137\103\117\x4e\x54\105\116\x54\x5f\x52\x41\116\107\105"); $content_range = $content_range_header ? preg_split("\x2f\133\136\60\x2d\71\x5d\x2b\57", $content_range_header) : null; $size = @$content_range[3]; $files = array(); if ($upload) { if (is_array($upload["\x74\x6d\160\137\x6e\x61\155\x65"])) { foreach ($upload["\164\155\160\x5f\x6e\141\155\145"] as $index => $value) { $files[] = $this->handle_file_upload($upload["\x74\x6d\160\x5f\x6e\x61\x6d\x65"][$index], $file_name ? $file_name : $upload["\156\x61\x6d\x65"][$index], $size ? $size : $upload["\163\x69\172\145"][$index], $upload["\x74\171\160\x65"][$index], $upload["\x65\x72\162\157\162"][$index], $index, $content_range); } } else { $files[] = $this->handle_file_upload(isset($upload["\x74\x6d\x70\137\x6e\141\155\x65"]) ? $upload["\x74\x6d\x70\x5f\x6e\x61\x6d\x65"] : null, $file_name ? $file_name : (isset($upload["\x6e\x61\x6d\x65"]) ? $upload["\156\141\x6d\x65"] : null), $size ? $size : (isset($upload["\163\151\172\x65"]) ? $upload["\x73\x69\x7a\x65"] : $this->get_server_var("\x43\x4f\116\124\105\116\x54\137\114\x45\116\107\x54\x48")), isset($upload["\x74\171\x70\x65"]) ? $upload["\164\x79\x70\145"] : $this->get_server_var("\x43\117\x4e\x54\105\x4e\x54\137\124\131\120\x45"), isset($upload["\x65\162\162\157\x72"]) ? $upload["\145\162\162\x6f\162"] : null, null, $content_range); } } $response = array($this->options["\160\141\162\141\155\x5f\156\x61\155\145"] => $files); return $this->generate_response($response, $print_response); } public function delete($print_response = true) { $file_names = $this->get_file_names_params(); if (empty($file_names)) { $file_names = array($this->get_file_name_param()); } $response = array(); foreach ($file_names as $file_name) { $file_path = $this->get_upload_path($file_name); $success = strlen($file_name) > 0 && $file_name[0] !== "\56" && is_file($file_path) && unlink($file_path); if ($success) { foreach ($this->options["\x69\155\x61\x67\x65\137\x76\145\x72\163\151\x6f\156\x73"] as $version => $options) { if (!empty($version)) { $file = $this->get_upload_path($file_name, $version); if (is_file($file)) { unlink($file); } } } } $response[$file_name] = $success; } return $this->generate_response($response, $print_response); } protected function basename($filepath, $suffix = null) { $splited = preg_split("\x2f\134\57\x2f", rtrim($filepath, "\57\40")); return substr(basename("\x58" . $splited[count($splited) - 1], $suffix), 1); } }

Function Calls

None

Variables

None

Stats

MD5 c63ef2ed183b1ba8699549704ab5b715
Eval Count 0
Decode Time 178 ms