Questions about how to select and open a file

Source: Internet
Author: User
The question about how to select a file and open it is now to import the excel table data to the database, now you can complete the import of a fixed excel file. How can I select a file for import? after clicking "import", I open the local file library and find the file to be imported, click "open" to complete the function of determining whether the file is an excel file. Give me some advice !! The code is as follows: PHPcode & lt ;? Phprequire_once
Now I want to import the excel table data to the database. now I can import a fixed excel file. How can I select a file for import? after clicking "import", I open the local file library and find the file to be imported, click "open" to complete the function of determining whether the file is an excel file. Give me some advice !! The code is as follows:
PHP code
  
  SetOutputEncoding ('gbk'); // ”data.xls refers to the excel file $ data-> read('data.xls ') to be imported to mysql; // This is the fixed file to be imported, instead of being fixed, you can choose your own !!! @ $ Db = mysql_connect ('2017. 0.0.1 ', 'root', '') or die (" cocould not connect to database. "); // connect to the database mysql_query (" set names 'gbk' "); // output the Chinese mysql_select_db ('openlab '); // select the database error_reporting (E_ALL ^ E_NOTICE ); mysql_query ("set names 'gbk'"); for ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++) {// Print the excel table data in a for loop with the following annotations/* for ($ j = 1; $ j <= $ data-> sheets [0] ['numcols']; $ j ++) {echo "\"". $ data-> sheets [0 ] ['Cells] [$ I] [$ j]. "\", ";}echo" "; * // the following code inserts [3 fields] of the excel table data into mysql, modify the following code based on the number of fields in your excel table! $ SQL = "INSERT INTO student VALUES ('". $ data-> sheets [0] ['cells '] [$ I] [1]. "','". $ data-> sheets [0] ['cells '] [$ I] [2]. "','". $ data-> sheets [0] ['cells '] [$ I] [3]. "','". $ data-> sheets [0] ['cells '] [$ I] [4]. "','". $ data-> sheets [0] ['cells '] [$ I] [5]. "','". $ data-> sheets [0] ['cells '] [$ I] [6]. "')"; echo $ SQL.'
'; $ Res = mysql_query ($ SQL) ;}?>


------ Solution --------------------
It is the effect of using php to upload and make a similar selection file. then, if you have a file, you can do whatever you want.
------ Solution --------------------
You can obtain the file attributes after uploading a php file.
------ Solution --------------------
This code is not correctly written. it is explained step by step.

Select and open the file. Is the process of uploading files using php. Find an example of php file upload.

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.