tp文件上传

public function uploadd()
    {
        $file = request()->file('file');
        $arr = [];
        if ($file) {
            // 验证文件并移动到项目uploads文件夹下
            $info = $file->validate(['size' => 1024 * 1024, 'ext' => 'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
            if ($info) {
                $arr['code'] = 1;
                // 获取文件路径
                $arr['msg'] = $info->getSaveName();
            } else {
                $arr['code'] = 2;
                $arr['msg'] = $file->getError();
            }
        } else {
            $arr['code'] = 3;
            $arr['msg'] = '没有上传文件';
        }
        return $arr;
    }
}
posted @ 2020-09-23 14:31  梦魇之瞳  阅读(111)  评论(0编辑  收藏  举报