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.