【html 页面】
上传Excel文件:【php页面】
//批量上传文件 public function upload() { if($_FILES["xls_file"]["name"]=='') { showmessage('对不起,请选择您要上传的文件!', HTTP_REFERER); return; } else if($_FILES["xls_file"]["type"]!='application/msexcel') { showmessage('对不起,您上传的文件格式不正确!', HTTP_REFERER); return; } else if($_FILES["xls_file"]["error"]>0) { showmessage('Error:'.$_FILES["xls_file"]["error"].'
', HTTP_REFERER); return; } else if(file_exists(PC_PATH.'modules/client/'.$_FILES["xls_file"]["name"])) { showmessage('对不起,文件'.$_FILES["xls_file"]["name"].'已上传,请选择其他文件或者将此文件重命名上传!', HTTP_REFERER); return; } else if(!file_exists(PC_PATH.'modules/client/'.$_FILES["xls_file"]["name"])) { move_uploaded_file($_FILES["xls_file"]["tmp_name"], PC_PATH.'modules/client/'.$_FILES["xls_file"]["name"]); } header("Content-Type:text/html;charset=utf-8"); require_once 'Excel/reader.php'; include_once "adodb5/adodb.inc.php";//调用adodb5类库 $data = new Spreadsheet_Excel_Reader();//创建对象 $data->setOutputEncoding('UTF-8');//设置文本输出编码 $excel = PC_PATH.'modules/client/'.$_FILES["xls_file"]["name"]; $data->read($excel);//读取Excel文件 $data->setOutputEncoding('gbk'); error_reporting(E_ALL ^ E_NOTICE); $clientInfo = array(); $count=0; for ($i = 6; $i <= $data->sheets[0]['numRows']; $i++) { $clientInfo['client']['catid'] = $data->sheets[0]['cells'][$i][1]; $clientInfo['client']['name'] = $data->sheets[0]['cells'][$i][2]; $clientInfo['client']['sex'] = $data->sheets[0]['cells'][$i][3]; $clientInfo['client']['address'] = $data->sheets[0]['cells'][$i][4]; $clientInfo['client']['qq'] = trim($data->sheets[0]['cells'][$i][5]); $clientInfo['client']['email'] = trim($data->sheets[0]['cells'][$i][6]); $clientInfo['client']['updatetime'] = SYS_TIME; $clientInfo['client']['inputtime'] = SYS_TIME; $this->db->set_model(12); //12对应于content模块对应的modelid (PHPCMS) if($this->db->add_content($clientInfo['client'])) { $count++; } } showmessage('客户成功录入'.$count.'条记录!', HTTP_REFERER); }