12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace app\api\controller\v1;
- use think\Controller;
- class Upload extends Controller
- {
- public function upfile(){
- $file = request()->file('uploadFile');
- // 移动到框架应用根目录/uploads/ 目录下
- $info = $file->validate([
- 'size'=>100*1024*1024,
- 'ext'=>'jpg,png,jpeg,doc,docx,xls,xlsx,pdf,ppt,pptx,apk,txt',
- // 'type'=>'image/jpeg,image/png,image/jpeg,application/vnd.android.package-archive,application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,text/plain,application/vnd.openxmlformats-officedocument.presentationml.presentation'
- ])
- ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads/files');
- if($info){
- $img = '/uploads/files/' . $info->getSaveName();
- $img = str_replace('\\', '/', $img);
- $data = array(
- 'status' => 'done',
- 'name' => request()->domain(true).$img,
- );
- }else{
- // 上传失败获取错误信息
- $data = array(
- 'status' => 'error',
- 'msg' => $file->getError(),
- );
- }
- throw new \think\exception\HttpResponseException(json($data));
- return;
- }
- }
|