コード例 #1
0
ファイル: inputTest.php プロジェクト: zhouyaozhouyao/tp5.0
 public function testSuperglobals()
 {
     Input::setFilter('trim');
     $_GET['get'] = 'get value ';
     $this->assertEquals('get value', Input::get('get'));
     $_POST['post'] = 'post value ';
     $this->assertEquals('post value', Input::post('post'));
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $this->assertEquals('post value', Input::param('post'));
     $this->assertEquals(null, Input::param('get'));
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $this->assertEquals('get value', Input::param('get'));
     $this->assertEquals(null, Input::param('post'));
     $this->assertEquals(null, Input::param('put'));
     $_REQUEST = array_merge($_GET, $_POST);
     $this->assertEquals('get value', Input::request('get'));
     session_start();
     $_SESSION['test'] = 'session value ';
     $this->assertEquals('session value', Input::session('test'));
     session_destroy();
     $_COOKIE['cookie'] = 'cookie value ';
     $this->assertEquals('cookie value', Input::cookie('cookie'));
     $_SERVER['REQUEST_METHOD'] = 'GET ';
     $this->assertEquals('GET', Input::server('REQUEST_METHOD'));
     $GLOBALS['total'] = 1000;
     $this->assertEquals(1000, Input::globals('total'));
     $this->assertEquals('testing', Input::env('APP_ENV'));
     //$_SERVER['PATH_INFO'] = 'path/info';
     //$path = $_SERVER['PATH_INFO'] ? explode('/', $_SERVER['PATH_INFO'])[0] : '';
     //$this->assertEquals($path, Input::path('0', ''));
     $_FILES = ['file' => ['name' => 'test.png', 'type' => 'image/png', 'tmp_name' => '/tmp/php5Wx0aJ', 'error' => 0, size => 15726]];
     $this->assertEquals('image/png', Input::file('file.type'));
 }
コード例 #2
0
ファイル: Request.php プロジェクト: xuyi5918/ipensoft
 /**
  * 获取上传的文件信息
  * @access public
  * @param string $name 名称
  * @return null|array|\think\File
  */
 public function file($name = '')
 {
     return Input::file($name, $this->file ?: $_FILES);
 }
コード例 #3
0
ファイル: Validate.php プロジェクト: xuyi5918/ipensoft
 /**
  * 验证上传文件大小
  * @access protected
  * @param mixed $value  字段值
  * @param mixed $rule  验证规则
  * @return bool
  */
 protected function fileSize($value, $rule)
 {
     $file = Input::file($value);
     if (empty($file)) {
         return false;
     }
     if (is_string($rule)) {
         $rule = explode(',', $rule);
     }
     if (is_array($file)) {
         foreach ($file as $item) {
             if ($item->getSize() > $rule) {
                 return false;
             }
         }
         return true;
     } else {
         return $file->getSize() <= $rule;
     }
 }