tp5 单文件上传接口
Posted 910624858
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tp5 单文件上传接口相关的知识,希望对你有一定的参考价值。
路由:
Route::post(\'upload\',\'task/task/upload\');
控制器代码:
//文件上传接口 public function upload() { $file = request()->file(\'img\'); if ($file) { $info = $file->move(ROOT_PATH . \'public\' . DS . \'uploads\'); if ($info) { // 成功上传后 获取上传信息 // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg $filepath = DS . \'uploads\' . DS . $info->getSaveName(); } else { // 上传失败获取错误信息 return json([\'code\' => 501, \'message\' => $file->getError()]); } } return json([\'code\' => 200, \'message\' => \'文件上传成功\', \'data\' =>$filepath]); }
postman:
以上是关于tp5 单文件上传接口的主要内容,如果未能解决你的问题,请参考以下文章
TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect(代码片段