php excel导入
来源:互联网 发布:怎样关闭windows防火墙 编辑:程序博客网 时间:2024/06/04 18:41
<?phpdate_default_timezone_set("prc");if (($_FILES["foot"]["size"] < 20000)&&($_FILES["foot"]["type"]=="application/octet-stream" )) { if ($_FILES["foot"]["error"] > 0) { echo "Return Code: " . $_FILES["foot"]["error"] . "<br />"; } else { // echo "Upload: " . $_FILES["foot"]["name"] . "<br />"; // echo "Type: " . $_FILES["foot"]["type"] . "<br />"; // echo "Size: " . ($_FILES["foot"]["size"] / 1024) . " Kb<br />"; // echo "Temp file: " . $_FILES["foot"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["foot"]["name"])) { echo $_FILES["foot"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["foot"]["tmp_name"], "upload/" . $_FILES["foot"]["name"]); require_once 'reader.php'; require_once "oleread.inc"; $data=new Spreadsheet_Excel_Reader(); $data->setOutputEncoding("utf-8"); $data->read( "upload/" . $_FILES["foot"]["name"]); $conn=mysql_connect('localhost','root','123456')or die("连接失败".mysql_errno());mysql_select_db("stu",$conn)or die("连接数据库失败".mysql_errno());mysql_query("set names 'gbk'"); $m=new match(); for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) { //将execl数据插入数据库 $i表示从excel的第$i行开始读取 $nameteamA=$data->sheets[0]['cells'][$i][1]; $nameteamA=iconv("utf-8","gbk",$nameteamA); $idteamA=$m->findteam($nameteamA); $nameteamB=$data->sheets[0]['cells'][$i][2]; $nameteamB=iconv("utf-8","gbk",$nameteamB); $idteamB=$m->findteam($nameteamB); $scoreA=$data->sheets[0]['cells'][$i][3]; $scoreB=$data->sheets[0]['cells'][$i][4]; if($scoreA>$scoreB){ $result=1; } if($scoreA<$scoreB){ $result=-1; } if($scoreA==$scoreB){ $result=0; } $endtime=0; $state=1; $starttime=$data->sheets[0]['cells'][$i][5]; $detail= $data->sheets[0]['cells'][$i][6]; $detail=iconv("utf-8","gbk",$detail); $timeflag= $data->sheets[0]['cells'][$i][7]; $locaild= $data->sheets[0]['cells'][$i][8]; $locaild=iconv("utf-8","gbk",$locaild); $id=$m->findchang($locaild); if(empty($id)){ $m->addchang($locaild); $id=$m->findchang($locaild); } $c= strtotime($starttime); mysql_query("set default gbk");$sql="insert into matches values('','$idteamA','$idteamB','$nameteamA','$nameteamB','$scoreA','$scoreB','$c','$endtime','$result','$state','$detail','$timeflag','$id');";$res=mysql_query($sql);if(!$res){echo "比赛添加失败";} } @unlink( "upload/" . $_FILES["foot"]["name"]); } } } else { $alert=iconv("utf-8","gbk","只能上传2M大小的(2003-2005)excel文件"); echo $alert; } class match{ public function findteam($nameteam){ $conn=mysql_connect('localhost','root','123456')or die("连接失败".mysql_errno());mysql_select_db("stu",$conn)or die("连接数据库失败".mysql_errno());mysql_query("set names 'gbk'");$sql="select id from team where tname='{$nameteam}';"; $res=mysql_fetch_array(mysql_query($sql));if(empty($res)){$sql="insert into team values('','$nameteam','');";mysql_query($sql);{}}return $res['id']; } function findchang($locaild){ $conn=mysql_connect('localhost','root','123456')or die("连接失败".mysql_errno());mysql_select_db("stu",$conn)or die("连接数据库失败".mysql_errno());mysql_query("set names 'gbk'");$sql="select id from chang where name='$locaild'"; $res=mysql_fetch_array(mysql_query($sql));if(!res){echo "查询失败".mysql_error();}return $res['id']; } function addchang($rs){ $conn=mysql_connect('localhost','root','123456')or die("连接失败".mysql_errno());mysql_select_db("stu",$conn)or die("连接数据库失败".mysql_errno());mysql_query("set names 'gbk'");$sql="insert into chang values('','$rs');";$res=mysql_query($sql);if(!$res){echo "场地添加失败";} } } ?>
download.php
<?php$name="data.xls"; $path="download/$name"; if(file_exists($path)){ header('Cache-control: max-age=31536000');header('Expires: '.gmdate('D, d M Y H:i:s', time() + 31536000).' GMT');header('Content-Encoding: none');header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel"); header( 'Content-Length: '.filesize($path));header("Content-Disposition:attachment;filename=".$name);readfile($path);exit; } else{ echo "文件不存在"; }?>
0 0
- PHP 导入Excel
- PHP导出导入Excel
- PHP导入Excel
- PHP导入Excel
- php导入excel文件
- php 导入excel
- php导入Excel
- PHP 导入excel数据
- php excel导入
- PHP Excel 导入mysql
- PHP导入Excel文件
- php导入excel
- php导入excel数据
- PHP导入excel
- php 导入excel 方法
- php excel导入 导出
- PHP原生excel导入
- php excel 表格导入
- 水题集
- OpenMesh修改CMakeLists文件之添加链接库
- GRE、PPTP、L2TP隧道协议
- HOOK钩子技术2 内联钩子Inline HOOK 通过DLL注入
- hduoj 5214 Movie 暴力
- php excel导入
- android singleline ...显示不全
- hdu 1789 Doing Homework again
- PPTP穿透NAT之深入分析
- 迅速掌握Spring框架
- Android 开发环境下载地址 -- 百度网盘 adt-bundle android-studio sdk adt 下载
- 内联函数(To be update)
- 浅谈WebService
- Spring和SpringMVC的区别