Php submits excel data to mysql for example. if The computer is installed with WIN7, an error occurs: The filename C: \ Windows \ Temp \ phpEA26.tmp is not readable.
You can also provide a piece of inserted code.
Reply to discussion (solution)
Insufficient permissions?
Specify upload_tmp_dir in php. ini to the appropriate directory.
The code for inserting MYSQL is as follows:
Error_reporting (E_ALL ^ E_NOTICE );
Require_once 'Conn. php ';
Mysql_query ("set names 'gbk '");
If ($ _ POST ){
$ Import_TmpFile = $ _ FILES ['file'] ['tmp _ name'];
Require_once 'Excel/reader. php ';
$ Data = new Spreadsheet_Excel_Reader ();
$ Data-> setOutputEncoding ('gbk ');
$ Data-> read ($ Import_TmpFile );
$ Array = array ();
For ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++ ){
For ($ j = 1; $ j <= $ data-> sheets [0] ['numcols']; $ j ++ ){
$ Array [$ I] [$ j] = $ data-> sheets [0] ['cells '] [$ I] [$ j];
}
}
Sava_data ($ array );
}
Function sava_data ($ array ){
$ Count = 0;
$ Total = 0;
Foreach ($ array as $ tmp ){
$ Isql = "Select t_id from test where t_id = '". $ tmp [1]. "'";
$ SQL = "Insert into test (t_title, t_date) value (";
$ SQL. = "'". $ tmp [1]. "', '". $ tmp [2]. "')";
If (! Mysql_num_rows (mysql_query ($ Isql ))){
If (mysql_query ($ SQL )){
$ Count ++;
}
}
$ Total ++;
}
Echo "script" alert ('total ". $ total. "Data entries, import ". $ count. "Data entries succeeded"); location = 'exceld. php'; script ";
}
Function ttodd ($ text ){
$ Jd1900 = GregorianToJD (1, 1, 1900)-2;
$ MyJd = $ text + $ jd1900;
$ MyDate = JDToGregorian ($ myJd );
$ MyDate = explode ('/', $ myDate );
$ MyDateStr = str_pad ($ myDate [2], 4, '0', STR_PAD_LEFT ). "-". str_pad ($ myDate [0], 2, '0', STR_PAD_LEFT ). "-". str_pad ($ myDate [1], 2, '0', STR_PAD_LEFT );
Return $ myDateStr;
}
?>
No error occurs, but data cannot be inserted. why ??
Directly spell out SQL statements
Debug the program step by step to see where it is going
If (! Mysql_num_rows (mysql_query ($ Isql ))){
If (mysql_query ($ SQL) {// if you enter here, you can use echo mysql_error (); to find out what is wrong
$ Count ++;
}