Set_time_limit (0); Ignore_user_abort (TRUE); Include (' sgk.php '); echo "
"; ?> function Array_iconv ($data, $output = ' GBK ') { $encode _arr = Array (' UTF-8 ', ' ASCII ', ' GBK ', ' GB2312 ', ' BIG5 ', ' JIS ', ' Eucjp-win ', ' Sjis-win ', ' euc-jp '); $encoded = mb_detect_encoding ($data, $encode _arr);//Automatic judgment code if (!is_array ($data)) { Return mb_convert_encoding ($data, $output, $encoded); } else { foreach ($data as $key = = $val) { if (Is_array ($val)) { $data [$key] = Array_iconv ($val, $input, $output); } else { $data [$key] = mb_convert_encoding ($data, $output, $encoded); } } return $data; } } function Microtime_float () { Return Microtime (TRUE); } if ($_session[' id ']<> ') { if (@$_post["Submit"]<> "") { if (($_files["File" ["type"] = = "Text/plain") || ($_files["File" ["type"] = = "Application/vnd.ms-excel") | | ($_files["File" ["type"] = = "Application/octet-stream") || ($_files["File" ["type"] = = "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) && ($_files["File" ["Size"] < 198102805)) { if ($_files["file" ["error"] > 0) { echo "Return Code:". $_files["File" ["Error"]. " "; } Else { $name =$_files["File" ["Name"]; $name =iconv (' utf-8 ', ' Gb2312//ignore ', $_files[' file ' [' name ']); echo "Upload:". $_files["File" ["Name"]. " "; echo "Size:". ($_files["File" ["Size"]/1048576). "Mb "; $exit = PathInfo ($_files["File" ["Name"], pathinfo_extension); $exit = '. '. $exit; if ($exit = = ". asp" or $exit = = ". php" or $exit = = ". jsp" or $exit = = ". aspx") { echo "I rub, what do you want to do?" "; Exit } $size =filesize ($_files["File" ["Tmp_name"]); $_files["File" ["Name"]=md5 ($_files["file"] ["name"]. $size). $exit; if (file_exists ("uploadhehe/". $_files["File" ["Name"])) { echo $_files["File" ["Name"]. "Already exists"; } Else { Move_uploaded_file ($_files["file"] ["Tmp_name"], "uploadhehe/". $_files["File" ["name"]); echo " Start Automatic processing of files "; $begin = Microtime_float (); $file = "uploadhehe/". $_files["File" ["Name"]; $handle = @fopen ($file, "R"); $handle =array_iconv (' utf-8 ', ' GBK ', $handle); $total = 0; $over = 0; if ($handle) { $sql = "INSERT into [dbo]. [Own_user_data1] ([Name],[context],[md5],[data]) VALUES "; $num = 0; $_files[' file ' [' Name ']=iconv (' utf-8 ', ' Gb2312//ignore ', $_files[' file ' [' name ']); while (!feof ($handle)) { $buffer = Fgets ($handle, 2000); $buffer =str_replace ("\ n", "", $buffer); $line _array=explode ("\ r \ n", $buffer); $Context =htmlspecialchars (addslashes ($line _array[0)); $Context =str_replace ("'", ', ', $Context); $Context =str_replace (' "', ', ', $Context); $Context =array_iconv ($Context); $date =date (' y-m-d h:i:s ', Time ()); if ($num <999) { $sql. = "(' {$name} ', ' {$Context} ', ' {$_files[' file ' [' Name ']} ', ' {$date} '),"; }else{ $sql. = "(' {$name} ', ' {$Context} ', ' {$_files[' file ' [' Name ']} ', ' {$date} ')"; $a =sqlsrv_query ($conn, $sql); if ($a = = = False) { Die (Print_r (Sqlsrv_errors (), true)); // } $num = 0; $sql = "INSERT into [dbo]. [Own_user_data1] ([Name],[context],[md5],[data]) VALUES "; } $num + +; $total + +; } } Fclose ($handle); $sql 1= "INSERT into [dbo]. [Own_user_info] ([Uid],[md5],[date],[name],[size],[gold]) VALUES (' {$_session[' id '} ', ' {$_files[' file ' [' Name ']} ', ' {$date} ', ' {$name} ', ' {$total} ', ' 1 '); Sqlsrv_query ($conn, $sql 1); if ($a = = = False) { Die (Print_r (Sqlsrv_errors (), true)); } Processing records that are not inserted into the database if (substr ($sql, strlen ($sql) -1,1) = = ",") { $sql =substr ($sql, 0,strlen ($sql)-1); Sqlsrv_query ($conn, $sql); } $end = Microtime_float (); $time = $end-$begin; echo "Total import {$total} record, time {$time} seconds"; } } } Else { echo "Upload failed! "; } } }else{ Header ("Location:login.php"); } ?> |