mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
修正request类的file方法
This commit is contained in:
@@ -48,7 +48,7 @@ class File extends SplFileObject
|
||||
|
||||
/**
|
||||
* 设置上传信息
|
||||
* @param bool $info 上传文件信息
|
||||
* @param array $info 上传文件信息
|
||||
* @return $this
|
||||
*/
|
||||
public function setUploadInfo($info)
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace think;
|
||||
|
||||
use think\Config;
|
||||
use think\Exception;
|
||||
use think\File;
|
||||
use think\Session;
|
||||
use think\Exception;
|
||||
|
||||
class Request
|
||||
{
|
||||
@@ -82,7 +82,7 @@ class Request
|
||||
protected $post = [];
|
||||
protected $request = [];
|
||||
protected $put;
|
||||
protected $delete;
|
||||
protected $delete;
|
||||
protected $session = [];
|
||||
protected $file = [];
|
||||
protected $cookie = [];
|
||||
@@ -151,7 +151,7 @@ class Request
|
||||
self::$hook = array_merge(self::$hook, $method);
|
||||
} else {
|
||||
self::$hook[$method] = $callback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,19 +210,19 @@ class Request
|
||||
if (!isset($info['path'])) {
|
||||
$info['path'] = '/';
|
||||
}
|
||||
$options = [];
|
||||
$queryString = '';
|
||||
$options = [];
|
||||
$queryString = '';
|
||||
if (isset($info['query'])) {
|
||||
parse_str(html_entity_decode($info['query']), $query);
|
||||
if (!empty($params)) {
|
||||
$params = array_replace($query, $params);
|
||||
$queryString = http_build_query($query, '', '&');
|
||||
$params = array_replace($query, $params);
|
||||
$queryString = http_build_query($query, '', '&');
|
||||
} else {
|
||||
$params = $query;
|
||||
$queryString = $info['query'];
|
||||
$params = $query;
|
||||
$queryString = $info['query'];
|
||||
}
|
||||
} elseif (!empty($params)) {
|
||||
$queryString = http_build_query($params, '', '&');
|
||||
$queryString = http_build_query($params, '', '&');
|
||||
}
|
||||
$server['REQUEST_URI'] = $info['path'] . ('' !== $queryString ? '?' . $queryString : '');
|
||||
$server['QUERY_STRING'] = $queryString;
|
||||
@@ -232,7 +232,7 @@ class Request
|
||||
$options['server'] = $server;
|
||||
$options['url'] = $server['REQUEST_URI'];
|
||||
$options['baseUrl'] = $info['path'];
|
||||
$options['pathinfo'] = ltrim($info['path'],'/');
|
||||
$options['pathinfo'] = ltrim($info['path'], '/');
|
||||
$options['method'] = $server['REQUEST_METHOD'];
|
||||
$options['domain'] = $server['HTTP_HOST'];
|
||||
self::$instance = new self($options);
|
||||
@@ -394,15 +394,15 @@ class Request
|
||||
public function path()
|
||||
{
|
||||
if (is_null($this->path)) {
|
||||
$suffix = Config::get('url_html_suffix');
|
||||
$pathinfo = $this->pathinfo();
|
||||
if(false === $suffix){
|
||||
$suffix = Config::get('url_html_suffix');
|
||||
$pathinfo = $this->pathinfo();
|
||||
if (false === $suffix) {
|
||||
// 禁止伪静态访问
|
||||
$this->path = $pathinfo;
|
||||
}elseif($suffix){
|
||||
} elseif ($suffix) {
|
||||
// 去除正常的URL后缀
|
||||
$this->path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i' , '', $pathinfo);
|
||||
}else{
|
||||
$this->path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i', '', $pathinfo);
|
||||
} else {
|
||||
// 允许任何后缀访问
|
||||
$this->path = preg_replace('/\.' . $this->ext() . '$/i', '', $pathinfo);
|
||||
}
|
||||
@@ -588,12 +588,12 @@ class Request
|
||||
* @access public
|
||||
* @param string|array $name 变量名
|
||||
* @param mixed $default 默认值
|
||||
* @param string|array $filter 过滤方法
|
||||
* @param string|array $filter 过滤方法
|
||||
* @return mixed
|
||||
*/
|
||||
public function param($name = '', $default = null, $filter = null)
|
||||
{
|
||||
if(is_array($name)){
|
||||
if (is_array($name)) {
|
||||
// 设置param
|
||||
$this->param = array_merge($this->param, $name);
|
||||
return;
|
||||
@@ -625,7 +625,7 @@ class Request
|
||||
* @access public
|
||||
* @param string|array $name 变量名
|
||||
* @param mixed $default 默认值
|
||||
* @param string|array $filter 过滤方法
|
||||
* @param string|array $filter 过滤方法
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($name = '', $default = null, $filter = null)
|
||||
@@ -637,13 +637,13 @@ class Request
|
||||
}
|
||||
return $this->input($this->get, $name, $default, $filter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置获取获取POST参数
|
||||
* @access public
|
||||
* @param string $name 变量名
|
||||
* @param mixed $default 默认值
|
||||
* @param string|array $filter 过滤方法
|
||||
* @param string|array $filter 过滤方法
|
||||
* @return mixed
|
||||
*/
|
||||
public function post($name = '', $default = null, $filter = null)
|
||||
@@ -661,14 +661,14 @@ class Request
|
||||
* @access public
|
||||
* @param string|array $name 变量名
|
||||
* @param mixed $default 默认值
|
||||
* @param string|array $filter 过滤方法
|
||||
* @param string|array $filter 过滤方法
|
||||
* @return mixed
|
||||
*/
|
||||
public function put($name = '', $default = null, $filter = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
return $this->put = is_null($this->put) ? $name : array_merge($this->put, $name);
|
||||
}
|
||||
}
|
||||
if (is_null($this->put)) {
|
||||
parse_str(file_get_contents('php://input'), $this->put);
|
||||
}
|
||||
@@ -680,7 +680,7 @@ class Request
|
||||
* @access public
|
||||
* @param string|array $name 变量名
|
||||
* @param mixed $default 默认值
|
||||
* @param string|array $filter 过滤方法
|
||||
* @param string|array $filter 过滤方法
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete($name = '', $default = null, $filter = null)
|
||||
@@ -690,7 +690,7 @@ class Request
|
||||
}
|
||||
if (is_null($this->delete)) {
|
||||
parse_str(file_get_contents('php://input'), $this->delete);
|
||||
}
|
||||
}
|
||||
return $this->input($this->delete, $name, $default, $filter);
|
||||
}
|
||||
|
||||
@@ -804,25 +804,25 @@ class Request
|
||||
// 获取全部文件
|
||||
$item = [];
|
||||
foreach ($array as $key => $val) {
|
||||
if($val instanceof File){
|
||||
if ($val instanceof File) {
|
||||
$item[$key] = $val;
|
||||
}else{
|
||||
} else {
|
||||
if (empty($val['tmp_name'])) {
|
||||
continue;
|
||||
}
|
||||
$item[$key] = new File($val['tmp_name'])->setUploadInfo($val);
|
||||
}
|
||||
$item[$key] = (new File($val['tmp_name']))->setUploadInfo($val);
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
} elseif (isset($array[$name])) {
|
||||
if($array[$name] instanceof File){
|
||||
if ($array[$name] instanceof File) {
|
||||
return $array[$name];
|
||||
} elseif (!empty($array[$name]['tmp_name'])){
|
||||
return new File($array[$name]['tmp_name'])->setUploadInfo($array[$name]);
|
||||
}
|
||||
} elseif (!empty($array[$name]['tmp_name'])) {
|
||||
return (new File($array[$name]['tmp_name']))->setUploadInfo($array[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -838,7 +838,7 @@ class Request
|
||||
return $this->env = array_merge($this->env, $name);
|
||||
} elseif (empty($this->env)) {
|
||||
$this->env = $_ENV;
|
||||
}
|
||||
}
|
||||
return $this->input($this->env, strtoupper($name), $default, $filter);
|
||||
}
|
||||
|
||||
@@ -854,12 +854,12 @@ class Request
|
||||
if (is_array($name)) {
|
||||
return $this->header = array_merge($this->header, $name);
|
||||
} elseif (empty($this->header)) {
|
||||
$header = [];
|
||||
$server = $this->server ?: $_SERVER;
|
||||
foreach($server as $key => $val) {
|
||||
if (0 === strpos($key,'HTTP_')) {
|
||||
$key = str_replace('_','-',strtolower(substr($key,5)));
|
||||
$header[$key] = $val;
|
||||
$header = [];
|
||||
$server = $this->server ?: $_SERVER;
|
||||
foreach ($server as $key => $val) {
|
||||
if (0 === strpos($key, 'HTTP_')) {
|
||||
$key = str_replace('_', '-', strtolower(substr($key, 5)));
|
||||
$header[$key] = $val;
|
||||
}
|
||||
}
|
||||
if (isset($server['CONTENT_TYPE'])) {
|
||||
@@ -867,14 +867,14 @@ class Request
|
||||
}
|
||||
if (isset($server['CONTENT_LENGTH'])) {
|
||||
$header['content-length'] = $server['CONTENT_LENGTH'];
|
||||
}
|
||||
}
|
||||
$this->header = array_change_key_case($header);
|
||||
}
|
||||
if ('' === $name) {
|
||||
return $this->header;
|
||||
}
|
||||
$name = str_replace('_','-',strtolower($name));
|
||||
return isset($this->header[$name]) ? $this->header[$name] : $default;
|
||||
$name = str_replace('_', '-', strtolower($name));
|
||||
return isset($this->header[$name]) ? $this->header[$name] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -931,7 +931,7 @@ class Request
|
||||
if (is_string($filter)) {
|
||||
$filter = explode(',', $filter);
|
||||
} else {
|
||||
$filter = (array)$filter;
|
||||
$filter = (array) $filter;
|
||||
}
|
||||
$filter[] = $default;
|
||||
if (is_array($data)) {
|
||||
@@ -976,7 +976,7 @@ class Request
|
||||
// 调用函数或者方法过滤
|
||||
$value = call_user_func($filter, $value);
|
||||
} else {
|
||||
if (strpos($filter,'/')) {
|
||||
if (strpos($filter, '/')) {
|
||||
// 正则过滤
|
||||
if (!preg_match($filter, $value)) {
|
||||
// 匹配不成功返回默认值
|
||||
@@ -1008,7 +1008,7 @@ class Request
|
||||
if (is_string($value) && preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) {
|
||||
$value .= ' ';
|
||||
}
|
||||
// TODO 其他安全过滤
|
||||
// TODO 其他安全过滤
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1052,7 +1052,7 @@ class Request
|
||||
* @access public
|
||||
* @param string $name 变量名
|
||||
* @param string $type 变量类型
|
||||
* @param bool $checkEmpty 是否检测空值
|
||||
* @param bool $checkEmpty 是否检测空值
|
||||
* @return mixed
|
||||
*/
|
||||
public function has($name, $type = 'param', $checkEmpty = false)
|
||||
@@ -1069,7 +1069,7 @@ class Request
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ($checkEmpty && '' === $param) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user