联系官方销售客服
1835022288
028-61286886
请问一下,为什么我这里设置了上传格式的限制,然后ID也对应了dr_ID 然后为什么我上传图片的时候比如jpg也还可以上传成功啊,。
表单代码:
<div class="layui-form-item layui-form-text"> <label class="layui-form-label col-md-2">*</label> <div style="margin-left: 110px;text-align: left;" class="layui-upload"> <input type="hidden" name="data[jlsc]" lay-verify="head" id="dr_jlsc" value=""> <button type="button" class="layui-btn layui-btn-primary" id="upload"> <i class="layui-icon"></i> 请上传你的简历(仅支持pdf/doc/docx格式) </button> </div> </div>
JS代码部分:
//layui触发上传按钮---简历上传// upload.render({ elem: '#upload', url: '/index.php?s=ltss&c=shangchuan&m=upload', field: "file_data", data: { file_data: function(){ return $('#upload').val(); }, {csrf_token()} : "{csrf_hash()}" }, before: function(obj){ //预读本地文件示例,不支持ie8 obj.preview(function(index, file, result){ }); }, done: function(res){ if (!res.id){ return layer.msg('<span style="color: #fff">'+res.msg+'</span>'); }else { if(res.code == 1){ $("#head").attr("value", res.id); return layer.msg('<span style="color: #fff">上传成功</span>'); }else{ return layer.msg('<span style="color: #fff">上传失败,请重试!</span>'); } } }, error: function(){ //请求异常回调 } });
PHP代码部分:
<?php namespace Phpcmf\Controllers; /** * 二次开发时可以修改本文件,不影响升级覆盖 */ class Shangchuan extends \Phpcmf\Home\Module { public function upload() { $files = $this->request->getFiles(); $p['exts'] = $files['file_data']->getClientExtension(); $p['size'] = 100; // 验证上传权限 $rt = \Phpcmf\Service::L('upload')->upload_file([ 'path' => '', 'form_name' => 'file_data', 'file_exts' => @explode(',', $p['exts']), 'file_size' => (int)$p['size'] * 1024 * 1024, 'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(), ]); if (!$rt['code']) { exit(dr_array2string($rt)); } // 附件归档 $data = \Phpcmf\Service::M('Attachment')->save_data($rt['data']); if (!$data['code']) { exit(dr_array2string($data)); } // 上传成功 if (IS_API_HTTP) { $data['data'] = [ 'id' => $data['code'], 'url' => $rt['data']['url'], ]; exit(dr_array2string($data)); } else { exit(dr_array2string(['code' => 1, 'msg' => dr_lang('上传成功'), 'id' => $data['code'], 'info' => $rt['data']])); } } }
后台上传字段部分:
ibuc2t