fileReader.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. $txtTable = [];
  3. $root = './assets/API/Universal/Revit/';
  4. //$folder = $_GET["folder"];
  5. $paths = array_diff(scandir($root), array('.', '..', 'Thumbs.db','MEP','other'));
  6. foreach ($paths as $value) {
  7. $path = scandir($root . "/" . $value);
  8. foreach ($path as $txt) {
  9. if (str_contains($txt, '.txt')) {
  10. $txt = $root . "/" . $value."/".$txt;
  11. if (file_exists($txt)) {
  12. $str = file_get_contents($txt);
  13. $str = str_replace("、",",",$str);
  14. $array = explode(":", $str);
  15. $data = [];
  16. for ($i = 1; $i < 10; $i++) {
  17. if ($i != 9) {
  18. $values = explode("\r\n", $array[$i]);
  19. array_push($data,$values[0]);
  20. } else {
  21. array_push($data,$array[$i]);
  22. }
  23. }
  24. array_push($data,$root . "/" . $value);
  25. array_push($txtTable,$data);
  26. }
  27. }
  28. }
  29. }
  30. print_r($txtTable);
  31. $serverName = "GMGIS\SQLEXPRESS"; //test server 201
  32. $username = 'BIMuser';
  33. $password = 'Component3444';
  34. $dbname = 'BIMComponents';
  35. $connectionInfo = array("Database"=>"$dbname", "UID"=>"$username", "PWD"=>"$password", "CharacterSet"=>"UTF-8");
  36. $conn = sqlsrv_connect($serverName, $connectionInfo);
  37. if($conn === false){
  38. die(print_r(sqlsrv_errors(), true));
  39. }
  40. for ($i = 0; $i < count($txtTable); $i++) {
  41. $sql = "INSERT INTO [BIMComponents].[dbo].[API_Table]
  42. ([APIName]
  43. ,[software]
  44. ,[detail]
  45. ,[revitVersion]
  46. ,[operate]
  47. ,[type]
  48. ,[keyword]
  49. ,[source]
  50. ,[notes]
  51. ,[filePath]
  52. )
  53. VALUES
  54. ('".$txtTable[$i][0]."'
  55. ,'".$txtTable[$i][1]."'
  56. ,'".$txtTable[$i][2]."'
  57. ,'".$txtTable[$i][3]."'
  58. ,'".$txtTable[$i][4]."'
  59. ,'".$txtTable[$i][5]."'
  60. ,'".$txtTable[$i][6]."'
  61. ,'".$txtTable[$i][7]."'
  62. ,'".$txtTable[$i][8]."'
  63. ,'".$txtTable[$i][9]."'
  64. );";
  65. //sqlsrv_query($conn, $sql);
  66. echo($sql."<br>");
  67. }
  68. sqlsrv_close($conn);