任意文本数据导入SQL SERVER
php代码
<?php set_time_limit(0); ignore_user_abort(true); include('sgk.php'); echo "<br><br>"; ?> <?php 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);//自动判断编码 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"] . "<br />"; } else { $name=$_FILES["file"]["name"]; $name=iconv('utf-8', 'GB2312//IGNORE', $_FILES['file']['name']); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1048576) . " Mb<br />"; $exit= pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION); $exit='.' .$exit; if ($exit==".asp" or $exit==".php" or $exit==".jsp" OR $exit==".aspx"){ echo "我擦,你想做什么?"; 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"] . " 已经存在 "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "uploadhehe/" . $_FILES["file"]["name"]); echo "<br>开始自动处理文件<br>"; $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); $sql1="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,$sql1); if( $a === false ) { die( print_r( sqlsrv_errors(), true)); } //处理没有插入到数据库的记录 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}条记录,耗时{$time}秒"; } } } else { echo "上传失败!"; } } }else{ header("Location: login.php"); } ?>
登入後複製
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
刺客信條陰影:貝殼謎語解決方案
1 個月前
By DDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
3 週前
By DDD
在哪裡可以找到原子中的起重機控制鑰匙卡
1 個月前
By DDD
如何修復KB5055523無法在Windows 11中安裝?
2 週前
By DDD
Inzoi:如何申請學校和大學
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)