修正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
*/
public function setUploadInfo($info)

View File

@@ -12,9 +12,9 @@
namespace think;
use think\Config;
use think\Exception;
use think\File;
use think\Session;
use think\Exception;
class Request
{
@@ -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);
@@ -396,13 +396,13 @@ class Request
if (is_null($this->path)) {
$suffix = Config::get('url_html_suffix');
$pathinfo = $this->pathinfo();
if(false === $suffix){
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);
}
@@ -593,7 +593,7 @@ class Request
*/
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;
@@ -804,21 +804,21 @@ 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]);
}
}
}
@@ -856,9 +856,9 @@ class Request
} 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)));
foreach ($server as $key => $val) {
if (0 === strpos($key, 'HTTP_')) {
$key = str_replace('_', '-', strtolower(substr($key, 5)));
$header[$key] = $val;
}
}
@@ -873,7 +873,7 @@ class Request
if ('' === $name) {
return $this->header;
}
$name = str_replace('_','-',strtolower($name));
$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)) {
// 匹配不成功返回默认值