php利用ExcelFileParser把excel导入数据库
这是一款实用的php教程利用excelfileparser把excel导入数据库教程,代码如下:
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>excel数据获取演示</title> <meta name="keywords" content="todo" /> <meta name="description" content="todo"/> </head> <body> <div> <div>excel数据获取演示</div> <div> <form method="post" action="/index/parse" enctype="multipart/form-data"> <input type="file" name="excel" value="" /> <input type="submit" name="submit" value="提交" /> </form> </div> </div> </body> </html>
parese.php文件,代码如下:
<?php
/**
* copyright (c) 2009,
* all rights reserved.
* 文件名:
* 摘 要:
*
* @author 星期八 [url=mailto:ixqbar@hotmail.com]ixqbar@hotmail.com[/url]
* @version
*/
public function parse()
{
/**
* $_files数组说明
* array(n) {
* ["表单文件框名称"] => array(5) {
* ["name"] => 提交文件名称
* ["type"] => 提交文件类型 excel为"application/vnd.ms-excel"
* ["tmp_name"] => 临时文件名称
* ["error"] => 错误(0成功1文件太大超过upload_max_filesize2文件太大超过max_file3上传不完整4没有上传文件)
* ["size"] => 文件大小(单位:kb)
* }
* }
*/
$return=array(0,'');
/**
* 判断是否提交
* is_uploaded_file(文件名称)用于确定指定的文件是否使用post方法上传,防止非法提交,通常和move_upload_file一起使用保存上传文件到指定的路径
*/
if(!isset($_files) || !is_uploaded_file($_files['excel']['tmp_name']))
{
$return=array(1,'提交不合法');
}
//处理
if(0 == $return[0])
{
import('@.util.excelparser');
$excel=new excelparser($_files['excel']['tmp_name']);
$return=$excel->main();
}
//输出处理
print_r($return);
?>文章链接:http://www.phprm.com/develop/fs5394.html
随便收藏,请保留本文地址!