excellfileparser Excel into the database tutorial Oh.
<! doctype html public "- // w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.jzread.com/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text / html; charset = utf-8" />
<title> excel data acquisition demo </ title>
<meta name = "keywords" content = "todo" />
<meta name = "description" content = "todo" />
</ head>
<body>
<div>
<div> excel data acquisition demo </ div>
<div>
<form method = "post" action = "/ index / parse" enctype = "multipart / form-data">
<input type = "file" name = "excel" value = "" />
<input type = "submit" name = "submit" value = "Submit" />
</ form>
</ div>
</ div>
</ body>
</ html> parese.php file
<? php
/ **
* copyright (c) 2009,
* all rights reserved.
* file name:
* Summary:
*
* @ author week eight [url = mailto: ixqbar@hotmail.com] ixqbar@hotmail.com [/ url]
* @version
* /
public function parse ()
{
/ **
* $ _files array description
* array (n) {
* ["Form File Box Name"] => array (5) {
* ["name"] => submit file name
* ["type"] => submit file type excel as "application / vnd.ms-excel"
* ["tmp_name"] => Temporary file name
* ["error"] => error (0 success 1 file is too large upload_max_filesize2 file is too large max_file3 upload is not complete 4 no upload file)
* ["size"] => file size (in kb)
*}
*}
* /
$ return = array (0, '');
/ **
* Judge whether to submit
* is_uploaded_file (file name) is used to determine whether the specified file using the post method to upload, to prevent the illegal submission, usually with move_upload_file Save the upload file to the specified path
* /
if (! isset ($ _ files) ||! is_uploaded_file ($ _ files ['excel'] ['tmp_name']))
{
$ return = array (1, 'Submit illegal');
}
//deal with
if (0 == $ return [0])
{
import ('@. util.excelparser');
$ excel = new excelparser ($ _ files ['excel'] ['tmp_name']);
$ return = $ excel-> main ();
}
// output processing
print_r ($ return);
?>