public function readHttpBody() { $input = file_get_contents("php://input"); $values = array(); if (!isset($_SERVER["CONTENT_TYPE"])) { return $input; } if (strpos($_SERVER["CONTENT_TYPE"], "application/x-www-form-urlencoded") === 0) { parse_str($input, $values); return $values; } else { if (strpos($_SERVER["CONTENT_TYPE"], "multipart/form-data") === 0) { if (!preg_match("/boundary=([a-zA-Z0-9]+)/", $_SERVER["CONTENT_TYPE"], $m)) { return $input; } $parts = explode('--' . $m[1], $input); foreach ($parts as $part) { if (trim($part) == '' || $part == '--') { continue; } list($header, $value) = explode("\r\n\r\n", $part); if (preg_match('/content\\-disposition\\:(?: *)form\\-data\\;(?: *)name="([^"]+)"(\\;(?: *)filename="([^"]+)")?/i', $header, $m)) { if (isset($m[2]) && $m[3] != '') { $return[$m[1]] = array($m[3], $value); } else { $return[$m[1]] = $value; } } } if (count($values)) { return $values; } else { return $input; } } else { return $input; } } }