uploadComponent.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. include("connectSQL_Component.php");
  3. $componentGroups = [];
  4. $componentGroup = [];
  5. $componentNames = [];
  6. $categories = [];
  7. $oldFilepath = "../../assets/glb/Revit元件/Components/Arch/MEP/";
  8. $oldFilepaths = [];
  9. $old = [];
  10. $newFilepath = "../../assets/glb/Revit元件/Components/";
  11. $newFilepaths = [];
  12. $paths = array_diff(scandir($oldFilepath), array('.', '..', 'Thumbs.db'));
  13. foreach($paths as $path){
  14. array_push($oldFilepaths, $oldFilepath.$path);
  15. }
  16. for($i = 0; $i < count($oldFilepaths); $i++){
  17. $files = scandir($oldFilepaths[$i]);
  18. for($j = 0; $j < count($files); $j++){
  19. if(str_contains($files[$j], "glb")){
  20. array_push($old, $oldFilepaths[$i]."/".$files[$j]);
  21. }
  22. }
  23. }
  24. $sql = "SELECT [componentGroup], [componentName], [category] FROM [BIMComponents].[dbo].[Component_Info]";
  25. $fetchResult = sqlsrv_query($conn, $sql);
  26. while ($row = sqlsrv_fetch_array($fetchResult)) {
  27. array_push($componentGroups, $row["componentGroup"]);
  28. array_push($componentNames, $row["componentName"]);
  29. array_push($categories, $row["category"]);
  30. }
  31. for($i = 0; $i < count($componentGroups); $i++) {
  32. $componentGroup = explode(",", $componentGroups[$i]);
  33. for($j = 0; $j < count($componentGroup) - 1; $j++) {
  34. array_push($newFilepaths, $newFilepath.$componentGroup[$j]."/".$categories[$i]."/".$componentNames[$i].".glb");
  35. }
  36. }
  37. $start = "";
  38. $end = [];
  39. $a = array_unique($componentNames);
  40. for($i = 0; $i < count($a); $i++) {
  41. for($j = 0; $j < count($old); $j++){
  42. if(str_contains($old[$j], $a[$i])){
  43. $start = $old[$j];
  44. }
  45. }
  46. for($j = 0; $j < count($newFilepaths); $j++){
  47. if(str_contains($newFilepaths[$j], $a[$i])){
  48. array_push($end, $newFilepaths[$j]);
  49. }
  50. }
  51. for($j = 0; $j < count($end); $j++){
  52. copy($start, $end[$j]);
  53. }
  54. $end = [];
  55. }
  56. ?>