<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.cn