您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

tp3.2中多个excel文件上传导入数据库示例

2024/4/4 16:22:40发布11次查看
模板页面/index.html
上传maxsize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg','xls');// 设置附件上传类型
// 上传文件
$info = $upload->upload();
if(!$info){// 上传错误提示错误信息
$this->error($upload->geterror());
}else{// 上传成功
foreach($info as $file){
$files='./public/'.$file['savepath'].$file['savename'];
vendor(excel.phpexcel);
vendor(excel.phpexcel.phpexcel_iofactory);
$phpexcel = new \phpexcel();
//var_dump($phpexcel);
$phpreader = new \phpexcel_iofactory();
//var_dump($phpreader);die;
$xlspath =$files ; //指定要读取的exls路径
//$type = 'excel2007'; //设置要解析的excel类型 excel5(2003或以下版本)或excel2007
//echo $xlspath;
$type = 'excel5';
$xlsreader = $phpreader->createreader($type);
$xlsreader->setreaddataonly(true);
$xlsreader->setloadsheetsonly(true);
$sheets = $xlsreader->load($xlspath);
//开始读取a
$sheet = $sheets->getsheet(0)->toarray(); //读取第一个工作表(注意编号从0开始) 如果读取多个可以做一个循环0,1,2,3....
//得到二维数组,每个小数组是excel表格内容的一行 里面包含此行的每列的数据
//echo '';
//print_r($sheet);
foreach($sheet as $k=>$v){
$model = m('student');// 取得成功上传的文件信息
$data['name']=$v[0];
$result=$model->add($data);
if($result){
$this->success(入库成功,u('index/excellist'));
}else{
$this->error(入库失败);
}
}
}
}
}
以上就介绍了tp3.2中多个excel文件上传导入数据库示例,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product