<style type="text/css">
<!--
@import url("../style/admin.css");
.STYLE1 {
color: #FF0000;
font-weight: bold;
}
.STYLE2 {color: #0033FF}
-->
</style>
<script>
function import_check(){
var f_content = form1.file.value;
var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.length)
fileext=fileext.toLowerCase()
if (fileext!='.xls')
{
alert("对不起,导入数据格式必须是xls格式文件哦,请您调整格式后重新上传,谢谢 !");
return false;
}
}
</script>
<table width="98%" border="0" align="center" style="margin-top:20px; border:1px solid #9abcde;">
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
<tr >
<td height="28" colspan="2" background="../skins/top_bg.gif"><label> <strong><a href="#">红利卡积分会员数据导入</a></strong></label></td>
</tr>
<tr>
<td width="18%" height="50"> 选择你要导入的数据表</td>
<td width="82%"><label>
<input name="file" type="file" id="file" size="50" />
</label>
<label>
<input name="button" type="submit" class="nnt_submit" id="button" value="导入数据" onclick="import_check();"/>
</label>
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#DDF0FF"> [<span class="STYLE1">注</span>]数据导入格式说明:</td>
</tr>
<tr>
<td colspan="2"> 1、其它.导入数据表文件必须是<strong>execel</strong>文件格式{.<span class="STYLE2">xls</span>}为扩展名.</td>
</tr>
<tr>
<td colspan="2"> 2、execel文件导入数据顺序必须如:会员名称 | 会员卡号 | 身份证 | 积份 | 注册时间 | 过期日期 | 联系电话号码 如下图:</td>
</tr>
<tr>
<td colspan="2"> <img src="pic/1.jpg" width="758" height="248" /></td>
</tr></form>
</table>
<?php
error_reporting(E_ALL ^ E_NOTICE);
if($_POST){
$Import_TmpFile = $_FILES['file']['tmp_name'];
require_once '../../inc/connect.php';
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('GB2312');
$data->read($Import_TmpFile);
$array =array();
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$array[$i][$j] = $data->sheets[0]['cells'][$i][$j];
}
}
sava_data($array);
}
function sava_data($array){
$count =0;
$total =0;
foreach( $array as $tmp){
$Isql = "Select inte_card from gx_integral where inte_card='".$tmp[2]."'";
$sql = "Insert into gx_integral(inte_name,inte_card,inte_status,inte_integral,inte_date,inte_date2,inte_tel) value(";
$sql.="'".$tmp[1]."','".$tmp[2]."','".$tmp[3]."','".$tmp[4]."','".TtoD($tmp[5])."','".TtoD($tmp[6])."','".$tmp[7]."')";
if(! mysql_num_rows(mysql_query($Isql) )){
if( mysql_query($sql) ){
$count++;
}
}
$total++;
}
echo "<script>alert('共有".$total."条数据,导入".$count."条数据成功');</script>";
}
function TtoD($text){
$jd1900 = GregorianToJD(1, 1, 1900)-2;
$myJd = $text+$jd1900;
$myDate = JDToGregorian($myJd);
$myDate = explode('/',$myDate);
$myDateStr = str_pad($myDate[2],4,'0', STR_PAD_LEFT)."-".str_pad($myDate[0],2,'0', STR_PAD_LEFT)."-".str_pad($myDate[1],2,'0', STR_PAD_LEFT);
return $myDateStr;
}
?>
这里是用到Spreadsheet_Excel_Reader组件了,那read.php文件我就不附上了,自己下一个吧,好了最后申明本站原创转载请注明: www.111cn.net