# 附件十一 TP5源码 上传文件入库类源码 上传文件及图片调用方法 核心代码仅仅两行 ~~~ $pic = $this->request->file($file_name); Upload::uploadPicture($pic,"",true,$rule); $file = $this->request->file($file_name); Upload::uploadFile($file,"",true,$rule); ~~~ * 上传图片 ~~~ public function uploadPicture($file_name = "file") { Config::set(['default_return_type' => 'json',]); if ($this->request->isPost()) { $pic = $this->request->file($file_name); if (isset($pic)) { if (is_array($pic) && !is_object($pic)){ return self::showReturnCodeWithOutData(1054, "只容许单张图片上传"); } $rule=[]; return Upload::uploadPicture($pic,"",true,$rule); } else { return self::showReturnCodeWithOutData(1010, "上传的图片不存在"); } } else { // dump($this->request); return self::showReturnCodeWithOutData(1002); } } ~~~ * 上传文件 ~~~ public function uploadFile($file_name = "file") { Config::set(['default_return_type' => 'json',]); if ($this->request->isPost()) { $file = $this->request->file($file_name); if (isset($pic)) { if (is_array($pic) && !is_object($pic)){ return self::showReturnCodeWithOutData(1054, "只容许文件上传"); } $rule=[]; return Upload::uploadFile($file,"",true,$rule); } else { return self::showReturnCodeWithOutData(1010, "上传的文件不存在"); } } else { return self::showJsonReturnCodeWithOutData(1002); } } ~~~