php using ExcelFileParser excel into the database

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags array content data data acquisition file files html http

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);
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.