thinkphp导入问题。

浏览:1360 发布日期:2013/03/25 分类:求助交流
现在在弄一个导入的,把excel数据专稿到数据中。程序运行到Vendor('Excel.reader'); // 加载reader类。这里就提示500错误呀。请大家指教下呀。
html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="__URL__/insert" name="form1" enctype="multipart/form-data">
<table cellspacing="0" cellpadding="0" border="1">
<tr>
<td ><input type="file" name="myfile" /> <input type="submit" class="mybutton" name="import" value="导入" ></td>
</tr>
</table>
</form>


</body>
</html>
控制器代码:
public function insert(){
header("Content-Type:text/html; charset=utf-8");
Vendor('Excel.reader'); // 加载reader类。
if(!$this->isPost())
{
$this->display();
}
else
{
if($_FILES['myfile']['name']!='')
{
$tmp_file=$_FILES['myfile']['tmp_name'];
$file_types=explode(".",$_FILES['myfile']['name']);
$file_type=$file_types[count($file_types)-1];
if(strtolower($file_type)!="xls"){
// echo "<span style=\"color:red;line-height: 25px;\">格式错误 <a href=\"#\" onclick=history.go(-1);>请返回</a> </span>";
$this->assign('jumpUrl',__URL__/insert);
$msg="格式错误,请重新上传";
$this->success($msg);
}
$savePath="Excel/xls/";
$str = date('Ymdhis');
$file_name=$str.".".$file_type;
if(!copy($tmp_file,$savePath.$file_name)){
//echo "<span style=\"color:red;line-height: 25px;\">上传错误请重试!!<a href=# onclick=history.go(-1);>[返回]</a></span>";
$this->assign('jumpUrl',__URL__/insert);
$msg="上传错误,请重新上传";
$this->success($msg);

}else{
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('utf-8');
$data->read("Excel/xls/".$file_name);
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$number=$data->sheets[0]['cells'][$i][1];
$passwd=$data->sheets[0]['cells'][$i][1];
$name=$data->sheets[0]['cells'][$i][2];
$catid=$data->sheets[0]['cells'][$i][3];
$sex=$data->sheets[0]['cells'][$i][4];
$tel=$data->sheets[0]['cells'][$i][5];
$home=$data->sheets[0]['cells'][$i][6];
$minzu=$data->sheets[0]['cells'][$i][7];
$Student=D("Student");
$info=array(
'number'=>$number,
'passwd'=>$passwd,
'name'=>$name,
'catid'=>$catid,
'sex'=>$sex,
'tel'=>$tel,
'home'=>$home,
'minzu'=>$minzu,
);
$Student->create($info);
$Student->add();
}
$this->assign('jumpUrl',__URL__);
$msg="学生信息导入成功";
$this->success($msg);
}
}
}
}
不知道为什么呀。有那位高手弄过这个的,可以共享一下代码吗???感激不尽。。
最佳答案
评论( 相关
后面还有条评论,点击查看>>