本文整理汇总了PHP中UploadedFile::createFromGlobals方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::createFromGlobals方法的具体用法?PHP UploadedFile::createFromGlobals怎么用?PHP UploadedFile::createFromGlobals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::createFromGlobals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFromGlobals
/**
* Instantiate request from php _SERVER variable
* @param array server
*/
public static function createFromGlobals()
{
$server = $_SERVER;
$uriParts = parse_url($server['REQUEST_URI']);
$uriParts['host'] = $server['SERVER_NAME'];
$uriParts['port'] = $server['SERVER_PORT'];
$uriParts['scheme'] = isset($server['REQUEST_SCHEME']) ? $server['REQUEST_SCHEME'] : (isset($server['HTTPS']) && $server['HTTPS'] == 'on' ? 'https' : 'http');
if (function_exists('getallheaders')) {
// a correct case already
$apacheHeaders = getallheaders();
foreach ($apacheHeaders as $header => $value) {
$headers[$header] = array_map('trim', explode(',', $value));
}
} else {
$headers = array();
// normalize the header key
foreach ($server as $key => $value) {
if (substr($key, 0, 5) != 'HTTP_') {
continue;
}
$name = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
$headers[$name] = array_map('trim', explode(',', $value));
}
}
$request = new static($server['REQUEST_METHOD'], new Uri($uriParts), $headers, Stream::createFromContents(file_get_contents('php://input')), $server, $_COOKIE, UploadedFile::createFromGlobals($_FILES));
if ($server['REQUEST_METHOD'] == 'POST' && in_array($request->getMediaType(), array('application/x-www-form-urlencoded', 'multipart/form-data'))) {
$request->setParsedBody($_POST);
}
return $request;
}