修正request类的file方法

This commit is contained in:
thinkphp
2016-06-21 11:53:38 +08:00
parent 70f146f3e3
commit 2281f1edb4
2 changed files with 51 additions and 51 deletions

View File

@@ -48,7 +48,7 @@ class File extends SplFileObject
/** /**
* 设置上传信息 * 设置上传信息
* @param bool $info 上传文件信息 * @param array $info 上传文件信息
* @return $this * @return $this
*/ */
public function setUploadInfo($info) public function setUploadInfo($info)

View File

@@ -12,9 +12,9 @@
namespace think; namespace think;
use think\Config; use think\Config;
use think\Exception;
use think\File; use think\File;
use think\Session; use think\Session;
use think\Exception;
class Request class Request
{ {
@@ -210,19 +210,19 @@ class Request
if (!isset($info['path'])) { if (!isset($info['path'])) {
$info['path'] = '/'; $info['path'] = '/';
} }
$options = []; $options = [];
$queryString = ''; $queryString = '';
if (isset($info['query'])) { if (isset($info['query'])) {
parse_str(html_entity_decode($info['query']), $query); parse_str(html_entity_decode($info['query']), $query);
if (!empty($params)) { if (!empty($params)) {
$params = array_replace($query, $params); $params = array_replace($query, $params);
$queryString = http_build_query($query, '', '&'); $queryString = http_build_query($query, '', '&');
} else { } else {
$params = $query; $params = $query;
$queryString = $info['query']; $queryString = $info['query'];
} }
} elseif (!empty($params)) { } elseif (!empty($params)) {
$queryString = http_build_query($params, '', '&'); $queryString = http_build_query($params, '', '&');
} }
$server['REQUEST_URI'] = $info['path'] . ('' !== $queryString ? '?' . $queryString : ''); $server['REQUEST_URI'] = $info['path'] . ('' !== $queryString ? '?' . $queryString : '');
$server['QUERY_STRING'] = $queryString; $server['QUERY_STRING'] = $queryString;
@@ -232,7 +232,7 @@ class Request
$options['server'] = $server; $options['server'] = $server;
$options['url'] = $server['REQUEST_URI']; $options['url'] = $server['REQUEST_URI'];
$options['baseUrl'] = $info['path']; $options['baseUrl'] = $info['path'];
$options['pathinfo'] = ltrim($info['path'],'/'); $options['pathinfo'] = ltrim($info['path'], '/');
$options['method'] = $server['REQUEST_METHOD']; $options['method'] = $server['REQUEST_METHOD'];
$options['domain'] = $server['HTTP_HOST']; $options['domain'] = $server['HTTP_HOST'];
self::$instance = new self($options); self::$instance = new self($options);
@@ -394,15 +394,15 @@ class Request
public function path() public function path()
{ {
if (is_null($this->path)) { if (is_null($this->path)) {
$suffix = Config::get('url_html_suffix'); $suffix = Config::get('url_html_suffix');
$pathinfo = $this->pathinfo(); $pathinfo = $this->pathinfo();
if(false === $suffix){ if (false === $suffix) {
// 禁止伪静态访问 // 禁止伪静态访问
$this->path = $pathinfo; $this->path = $pathinfo;
}elseif($suffix){ } elseif ($suffix) {
// 去除正常的URL后缀 // 去除正常的URL后缀
$this->path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i' , '', $pathinfo); $this->path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i', '', $pathinfo);
}else{ } else {
// 允许任何后缀访问 // 允许任何后缀访问
$this->path = preg_replace('/\.' . $this->ext() . '$/i', '', $pathinfo); $this->path = preg_replace('/\.' . $this->ext() . '$/i', '', $pathinfo);
} }
@@ -593,7 +593,7 @@ class Request
*/ */
public function param($name = '', $default = null, $filter = null) public function param($name = '', $default = null, $filter = null)
{ {
if(is_array($name)){ if (is_array($name)) {
// 设置param // 设置param
$this->param = array_merge($this->param, $name); $this->param = array_merge($this->param, $name);
return; return;
@@ -804,21 +804,21 @@ class Request
// 获取全部文件 // 获取全部文件
$item = []; $item = [];
foreach ($array as $key => $val) { foreach ($array as $key => $val) {
if($val instanceof File){ if ($val instanceof File) {
$item[$key] = $val; $item[$key] = $val;
}else{ } else {
if (empty($val['tmp_name'])) { if (empty($val['tmp_name'])) {
continue; continue;
} }
$item[$key] = new File($val['tmp_name'])->setUploadInfo($val); $item[$key] = (new File($val['tmp_name']))->setUploadInfo($val);
} }
} }
return $item; return $item;
} elseif (isset($array[$name])) { } elseif (isset($array[$name])) {
if($array[$name] instanceof File){ if ($array[$name] instanceof File) {
return $array[$name]; return $array[$name];
} elseif (!empty($array[$name]['tmp_name'])){ } elseif (!empty($array[$name]['tmp_name'])) {
return new File($array[$name]['tmp_name'])->setUploadInfo($array[$name]); return (new File($array[$name]['tmp_name']))->setUploadInfo($array[$name]);
} }
} }
} }
@@ -854,12 +854,12 @@ class Request
if (is_array($name)) { if (is_array($name)) {
return $this->header = array_merge($this->header, $name); return $this->header = array_merge($this->header, $name);
} elseif (empty($this->header)) { } elseif (empty($this->header)) {
$header = []; $header = [];
$server = $this->server ?: $_SERVER; $server = $this->server ?: $_SERVER;
foreach($server as $key => $val) { foreach ($server as $key => $val) {
if (0 === strpos($key,'HTTP_')) { if (0 === strpos($key, 'HTTP_')) {
$key = str_replace('_','-',strtolower(substr($key,5))); $key = str_replace('_', '-', strtolower(substr($key, 5)));
$header[$key] = $val; $header[$key] = $val;
} }
} }
if (isset($server['CONTENT_TYPE'])) { if (isset($server['CONTENT_TYPE'])) {
@@ -873,7 +873,7 @@ class Request
if ('' === $name) { if ('' === $name) {
return $this->header; return $this->header;
} }
$name = str_replace('_','-',strtolower($name)); $name = str_replace('_', '-', strtolower($name));
return isset($this->header[$name]) ? $this->header[$name] : $default; return isset($this->header[$name]) ? $this->header[$name] : $default;
} }
@@ -931,7 +931,7 @@ class Request
if (is_string($filter)) { if (is_string($filter)) {
$filter = explode(',', $filter); $filter = explode(',', $filter);
} else { } else {
$filter = (array)$filter; $filter = (array) $filter;
} }
$filter[] = $default; $filter[] = $default;
if (is_array($data)) { if (is_array($data)) {
@@ -976,7 +976,7 @@ class Request
// 调用函数或者方法过滤 // 调用函数或者方法过滤
$value = call_user_func($filter, $value); $value = call_user_func($filter, $value);
} else { } else {
if (strpos($filter,'/')) { if (strpos($filter, '/')) {
// 正则过滤 // 正则过滤
if (!preg_match($filter, $value)) { if (!preg_match($filter, $value)) {
// 匹配不成功返回默认值 // 匹配不成功返回默认值