diff --git a/application/chengji/controller/Index.php b/application/chengji/controller/Index.php index 79fe73e0..79b71c08 100644 --- a/application/chengji/controller/Index.php +++ b/application/chengji/controller/Index.php @@ -270,7 +270,7 @@ class Index extends Base // 获取表单上传文件 $file = request()->file('file'); - halt($file); + // 上传文件并返回结果 $data = upload($list,$file,true); diff --git a/application/chengji/view/index/biaolu.html b/application/chengji/view/index/biaolu.html index e00628c8..498751bc 100644 --- a/application/chengji/view/index/biaolu.html +++ b/application/chengji/view/index/biaolu.html @@ -36,13 +36,13 @@ layui.use('upload', function(){ ,url: "{:url('upload')}" //上传接口 ,done: function(res){ if(res.val == 1){ - $('#url').val('..\\public\\uploads\\chengji\\' + res.url); + $('#url').val(res.url); } layer.msg(res.msg); } ,data: { text: '考试成绩' - ,serurl:'..\\public\\uploads\\chengji\\' + ,serurl:'chengji\\' } ,acceptMime:'.xls,.xlsx' diff --git a/application/common.php b/application/common.php index 1d1ebce9..a344b878 100644 --- a/application/common.php +++ b/application/common.php @@ -206,11 +206,15 @@ function teacherNames($list = array()) */ function upload($list,$file,$isSave=false) { + // 声明默认目录 + $myrul = '..\public\uploads\\'; + // 实例化文件数据模型 $field = new \app\system\model\Fields; // 移动到框架应用根目录/uploads/ 目录下 - $info = $file->move($list['serurl']); + $info = $file->move($myrul.$list['serurl']); + // 如果上传成功 if(!$info){ @@ -219,12 +223,16 @@ function upload($list,$file,$isSave=false) return $data; } + + // 成功上传后 获取上传信息 $list['category'] = $info->getExtension(); - $list['url'] = $info->getSaveName(); + $list['url'] = $list['serurl'].$info->getSaveName(); $list['newname'] = $info->getFilename(); $list['hash'] = $info->hash('sha1'); $list['userid'] = session('userid'); + $list['oldname'] = $info->getInfo('name'); + $list['fieldsize'] = $info->getInfo('size'); // 如果需要保存文件 @@ -237,7 +245,7 @@ function upload($list,$file,$isSave=false) $data = array( 'msg'=>'上传成功' ,'val'=>true - ,'url'=>$list['url'] + ,'url'=>$myrul.$list['serurl'].$info->getSaveName() ); }else{ $data = array( @@ -249,7 +257,7 @@ function upload($list,$file,$isSave=false) $data = array( 'msg'=>'上传成功' ,'val'=>true - ,'url'=>$list['url'] + ,'url'=>$myrul.$list['serurl'].$info->getSaveName() ); } diff --git a/application/system/controller/Fields.php b/application/system/controller/Fields.php index 4da296f4..0b19b3b5 100644 --- a/application/system/controller/Fields.php +++ b/application/system/controller/Fields.php @@ -63,60 +63,23 @@ class Fields extends Base return json($data); } - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ - public function create() + + // 下载文件 + public function download($id) { - // + // 实例化文件数据模型 + $fl = new FL; + // 查询文件信息 + $filist = $fl->where('id',$id)->find(); + + // 下载文件 + $download = new \think\response\Download('\uploads\student\student_template.xlsx'); + + return $download->name('student_template.xlsx'); + } - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) - { - // - } - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - // - } - - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ - public function edit($id) - { - // - } - - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) - { - // - } /** * 删除指定资源 diff --git a/application/system/view/fields/index.html b/application/system/view/fields/index.html index ff80c598..1bd15c4e 100644 --- a/application/system/view/fields/index.html +++ b/application/system/view/fields/index.html @@ -56,7 +56,7 @@ @@ -107,17 +107,11 @@ var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值) var tr = obj.tr; //获得当前行 tr 的DOM对象 switch(layEvent){ - case 'detail':// 查看 - layer.msg('查看' + data.id); - break; case 'del':// 删除 - cjgl.del(obj,"/school"); + cjgl.del(obj,"/fields"); break; - case 'edit':// 编辑 - cjgl.add('编辑单位','/school/'+obj.data.id+'/edit','650','500'); - break; - case 'status':// 状态 - cjgl.status(obj,"{:url('setstatus')}"); + case 'download':// 编辑 + cjgl.add('下载文件','/fields/dwonload/'+obj.data.id,'650','500'); break; }; }); diff --git a/public/public/uploads/chengji/20190706/22ab71f7370fc4e35fe5156fc36604ff.xls b/public/public/uploads/chengji/20190706/22ab71f7370fc4e35fe5156fc36604ff.xls new file mode 100644 index 00000000..f0665e5b Binary files /dev/null and b/public/public/uploads/chengji/20190706/22ab71f7370fc4e35fe5156fc36604ff.xls differ diff --git a/public/public/uploads/chengji/20190706/929753f87b7f19c7f3b3fad811bbd275.xls b/public/public/uploads/chengji/20190706/929753f87b7f19c7f3b3fad811bbd275.xls new file mode 100644 index 00000000..f0665e5b Binary files /dev/null and b/public/public/uploads/chengji/20190706/929753f87b7f19c7f3b3fad811bbd275.xls differ