Thinkphp5.1上传Excel

1,controller :\app\项目名称\controller\Ai.php
public function show_import_web(){
$this->fetch = true;
}
2,view:\app\项目名称\view\Ai\show_import_web.html1
1
< type=“text/javascript” src="/files/layui/layui.js">

<legend>数据导入</legend>
 <legend>二、上传Excel文件</legend>
 </fieldset>
    <button type="button" class="layui-btn layui-btn-primary" id="update-excel-btn">只允许Excel文件</button>
</div>
<div class="layui-form-item">
    <div class="layui-input-block">
   <button class="layui-btn" lay-submit="" lay-filter="import_excel_btn">立即提交</button>
   </div>
</div>

< script language=“javascript”>
layui.use([‘form’, ‘upload’], function(){
var form = layui.form,upload = layui.upload;
//监听提交
form.on(‘submit(import_excel_btn)’, function(data){
// layer.msg(‘正在提交处理,请稍候…’, { icon: 16,time: 100000,shade : [0.5 , ‘#000’ , true] });
});
upload.render({ //允许上传的文件后缀
elem: ‘#update-excel-btn’
,url: ‘/lawyer/ai/upload_ai_data’
,accept: ‘file’ //普通文件
,exts: ‘xls|xlsx|csv’ //只允许上传excel文件
,done: function(res){
if(res.code==0){
layer.alert(res.msg);
}else{
layer.alert(res.msg);
}
}
});
});
< /script>
3,controller :\app\项目名称\controller\Ai.php
public function upload_ai_data(){
include ROOT_PATH . ‘include’ . DS . ‘PHPExcel-1.8.0’ . DS . ‘PHPExcel.php’;
$file = request()->file(‘file’);
$info = f i l e − > m o v e ( ′ . . / . . / f i l e . ∗ ∗ ∗ . c o m ′ ) ; i f ( file->move( '../../file.***.com'); if( file>move(../../file..com);if(info){
//获取上传到后台的文件名
$fileName = $info->getSaveName();
//获取文件后缀
$suffix = i n f o − > g e t E x t e n s i o n ( ) ; / / 判 断 哪 种 类 型 i f ( info->getExtension(); //判断哪种类型 if( info>getExtension();//if(suffix == “xlsx”){
$reader = \ =PHPExcel_IOFactory::createReader(‘Excel2007’);
}else{
$reader = \PHPExcel_IOFactory::createReader(‘Excel5’);
}
}else{
$this->error(‘文件过大或格式不正确导致上传失败-_-!’);
}
$get_path_name = $info->getPathname();
$excel = r e a d e r − > l o a d ( " reader->load(" reader>load("get_path_name",$encode = ‘utf-8’);
$sheet = $excel->getSheet(0);
$row_num = $sheet->getHighestRow();
//获取总列数
$col_num = $sheet->getHighestColumn();
c o l u m = a r r a y ( ) ; f o r ( colum = array(); for ( colum=array();for(i=0; i < = 6 ; i<=6; i<=6;i++){
$s = s h e e t − > g e t C e l l B y C o l u m n A n d R o w ( sheet->getCellByColumnAndRow( sheet>getCellByColumnAndRow(i,1)->getValue();
$colum[] = KaTeX parse error: Expected 'EOF', got '}' at position 12: s; }̲ if(colum[0] == “***” && $colum[1] == “***” && $colum[2] == “***” && $colum[3] == “***” && $colum[4] == “***” && $colum[5] == "**"){
c r e a t e t i m e = d a t e ( ′ Y − m − d H : i : s ′ , createtime = date('Y-m-d H:i:s', createtime=date(YmdH:i:s,this->now);
$userinfo = helper(‘Auth’)->user();
$lawyerid = $userinfo[‘Member’][‘user_id’];
$data = []; //数组形式获取表格数据
s u m = 0 ; f o r ( sum = 0; for ( sum=0;for(i = 2; $i <= $row_num; $i++) {
$data[‘question’] = s h e e t − > g e t C e l l ( " A " . sheet->getCell("A". sheet>getCell("A".i)->getValue();
$data[‘sex’] = s h e e t − > g e t C e l l ( " B " . sheet->getCell("B". sheet>getCell("B".i)->getValue();
$data[‘marriage’] = e x c e l − > g e t A c t i v e S h e e t ( ) − > g e t C e l l ( " C " . excel->getActiveSheet()->getCell("C". excel>getActiveSheet()>getCell("C".i)->getValue();
$data[‘raise’] = e x c e l − > g e t A c t i v e S h e e t ( ) − > g e t C e l l ( " D " . excel->getActiveSheet()->getCell("D". excel>getActiveSheet()>getCell("D".i)->getValue();
$data[‘assets’] = e x c e l − > g e t A c t i v e S h e e t ( ) − > g e t C e l l ( " E " . excel->getActiveSheet()->getCell("E". excel>getActiveSheet()>getCell("E".i)->getValue();
$data[‘house_property’] = e x c e l − > g e t A c t i v e S h e e t ( ) − > g e t C e l l ( " F " . excel->getActiveSheet()->getCell("F". excel>getActiveSheet()>getCell("F".i)->getValue();
$data[‘debt’] = e x c e l − > g e t A c t i v e S h e e t ( ) − > g e t C e l l ( " G " . excel->getActiveSheet()->getCell("G". excel>getActiveSheet()>getCell("G".i)->getValue();
if( $data[‘sex’] == “” || $data[‘sex’] == NULL){
$data[‘sex’] = 0;
}
if( $data[‘marriage’] == “” || $data[‘sex’] == NULL){
$data[‘marriage’] = 0;
}
if( $data[‘raise’] == “” || $data[‘sex’] == NULL){
$data[‘raise’] = 0;
}
if( $data[‘assets’] == “” || $data[‘sex’] == NULL){
$data[‘assets’] = 0;
}
if( $data[‘house_property’] == “” || $data[‘sex’] == NULL){
$data[‘house_property’] = 0;
}
if( $data[‘debt’] == “” || $data[‘sex’] == NULL){
$data[‘debt’] = 0;
}
q t = D b : : c o n n e c t ( qt = Db::connect( qt=Db::connect(this->_db_config)->table(‘fa_ai_question’)->field(‘id’)->where([
‘question’ => d a t a [ ′ q u e s t i o n ′ ] ] ) − > s e l e c t ( ) ; i f ( ! data['question'] ])->select(); if(! data[question]])>select();if(!qt){
//将数据保存到数据库
r e s = D b : : c o n n e c t ( res = Db::connect( res=Db::connect(this->_db_config)->table(‘fa_ai_question’)->insert([‘question’ => $data[‘question’], ‘lawyerid’ => l a w y e r i d , ′ c r e a t e t i m e ′ = > lawyerid,'createtime'=> lawyerid,createtime=>createtime, ‘sex’ => $data[‘sex’],‘marriage’ => $data[‘marriage’],‘raise’ => $data[‘raise’],‘assets’ => $data[‘assets’], ‘house_property’ => $data[‘house_property’], ‘debt’ => d a t a [ ′ d e b t ′ ] ] ) ; i f ( data['debt']]); if( data[debt]]);if(res){
$res = 0;
}else{
$res = 1;
}
}
$sum += KaTeX parse error: Expected 'EOF', got '}' at position 18: …s; }̲ if…sum == 0){
r e t = [ " c o d e " = > 0 , " m s g " = > " 上 传 成 功 " , " d a t a " = > [ ] ] ; e c h o ( j s o n e n c o d e ( ret = ["code"=>0, "msg"=>"上传成功", "data"=>[] ]; echo(json_encode( ret=["code"=>0,"msg"=>"","data"=>[]];echo(jsonencode(ret));
exit;
}else{
r e t = [ " c o d e " = > 0 , " m s g " = > " " , " d a t a " = > [ ] ] ; e c h o ( j s o n e n c o d e ( ret = ["code"=>0, "msg"=>"", "data"=>[] ]; echo(json_encode( ret=["code"=>0,"msg"=>"","data"=>[]];echo(jsonencode(ret));
exit;
}
}else{
r e t = [ " c o d e " = > 1 , " m s g " = > " 格 式 不 正 确 " , " d a t a " = > [ ] ] ; e c h o ( j s o n e n c o d e ( ret = ["code"=>1, "msg"=>"格式不正确", "data"=>[] ]; echo(json_encode( ret=["code"=>1,"msg"=>"","data"=>[]];echo(jsonencode(ret));
exit;
}
}
/仅供参考
/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: thinkphp5.1是一款基于PHP语言的MVC框架,它采用了Laravel框架中的一些优秀设计思想,并在此基础上进行了改进和优化,是一款颇受欢迎的PHP框架。 该框架具有非常完善的文档和教程,学习起来非常容易。它的核心思想是“约定优于配置”,通过一些默认的规则来简化代码,提高开发效率。同时,它也提供了很多实用的工具和函数,如请求对象、响应对象、验证器、缓存处理、日志记录等,使得开发者能够更加便捷地实现业务逻辑。 在源码方面,thinkphp5.1采用了比较优秀的代码结构和注释规范,代码风格清晰易读,符合现代编程的标准。同时,它也支持非常灵活的扩展机制,可以通过composer方式引入其他第三方组件来扩展功能。 总的来说,thinkphp5.1源码是一款非常优秀的PHP框架,具有清晰的代码结构、丰富的功能和非常好的可扩展性,适合开发各种规模的Web应用程序。 ### 回答2: ThinkPHP 5.1是一个基于MVC设计模式的PHP开源框架,它的源码是开放的,可以供开发者进行学习和使用。通过阅读ThinkPHP 5.1源码,开发者可以深入了解框架的核心设计思想和运行原理,从而更好地进行二次开发和定制。ThinkPHP 5.1源码的主要特点包括:使用面向对象的编程思想,提供了丰富的内置库函数和类库,支持依赖注入和控制反转,提供了强大的缓存机制,支持多种数据库操作,具有良好的安全性和可扩展性。此外,ThinkPHP 5.1还提供了详细的文档和示例代码,方便开发者学习和使用。总之,ThinkPHP 5.1源码为PHP开发者提供了强有力的支持,帮助开发者快速高效地开发出安全、稳定、高性能的web应用程序。 ### 回答3: thinkphp5.1源码是一个基于PHP的开发框架,它的思想是快速、可靠、简单、灵活,它提供了许多丰富的功能,包括模板引擎、数据库访问、缓存机制等等。 thinkphp5.1源码是一个开放源代码的框架,目前为止已经发展成为非常成熟的架构体系,拥有非常多的使用者和开发者,也得到了非常多的好评和支持。 thinkphp5.1源码的特点是快速开发、规范化开发、灵活、可扩展,它采用MVC的设计模式,在架构上很好地实现了分层开发原则,从而提高了开发效率和代码的可维护性。 此外,thinkphp5.1源码在数据库访问、缓存机制、模板引擎等方面也都有很好的支持,通过它们能够更好地管理数据、提高应用的性能和减少开发周期。 总之,thinkphp5.1源码具有很好的可用性和可扩展性,它已经成为PHP开发者中的主流框架之一,许多项目都已经采用了它的开发方式,包括PHP电商、PHP CMS等等,而且它也在不断不断地完善,使得它在未来的开发过程中仍然能保持其领先地位。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值