Home > php教程 > php手册 > php利用ExcelFileParser把excel导入数据库

php利用ExcelFileParser把excel导入数据库

WBOY
Release: 2016-05-26 15:21:56
Original
1376 people have browsed it

这是一款实用的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>
Copy after login

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,&#39;&#39;);  
/**  
* 判断是否提交  
* is_uploaded_file(文件名称)用于确定指定的文件是否使用post方法上传,防止非法提交,通常和move_upload_file一起使用保存上传文件到指定的路径  
*/  
if(!isset($_files) || !is_uploaded_file($_files[&#39;excel&#39;][&#39;tmp_name&#39;]))  
{  
    $return=array(1,&#39;提交不合法&#39;);  
}  
//处理  
if(0 == $return[0])  
{  
    import(&#39;@.util.excelparser&#39;);  
    $excel=new excelparser($_files[&#39;excel&#39;][&#39;tmp_name&#39;]);  
    $return=$excel->main();  
}
//输出处理  
print_r($return);  
?>
Copy after login


文章链接:

随便收藏,请保留本文地址!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template