Guest User

Untitled

a guest
Mar 29th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. <?php
  2.  
  3. require "PHPExcel/IOFactory.php";
  4.  
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "1234";
  8. $dbname = "msanson";
  9.  
  10. if(isset($_POST["upload"])){
  11. $inputfilename = $_FILES["file"]["tmp_name"];
  12. $exceldata = array();
  13.  
  14. $conn = mysqli_connect($servername,$username,$password,$dbname);
  15.  
  16. if(!$conn){
  17.  
  18. die("Baglantı yapılamadı:". mysqli_connect_error());
  19.  
  20. }
  21.  
  22. try{
  23.  
  24. $inputfiletype = PHPExcel_IOFactory::identify($inputfilename);
  25. $objReader = PHPExcel_IOFactory::createReader($inputfiletype);
  26. $objPHPExcel = $objReader->load($inputfilename);
  27.  
  28. }catch(Exception $e){
  29.  
  30. die('Yükleme hatası "'.pathinfo($inputfilename,PATHINFO_BASNAME).'":'.$e->getMassage());
  31.  
  32. }
  33.  
  34.  
  35. $sheet = $objPHPExcel->getSheet(0);
  36. $highestRow = $sheet->getHighestRow();
  37. $highestColumn = $sheet->getHighestColumn();
  38.  
  39. for($row = 1; $row <= $highestRow; $row++){
  40.  
  41. $rowData = $sheet->rangeToArray('A'.$row.':'.$highestColumn.$row, NULL,TRUE,FALSE);
  42.  
  43. $sql = "INSERT INTO msanlar
  44. il = ".$rowData[0][0].",
  45. Santral = ".$rowData[0][1].",
  46. MsanID = ".$rowData[0][4].",
  47. MsanAD = ".$rowData[0][9].",
  48. SignallingIP = ".$rowData[0][11].",
  49. RTPIP = ".$rowData[0][10].",
  50. OAMIP = ".$rowData[0][12].",
  51. Firma = ".$rowData[0][2].",
  52. MsanTipi = ".$rowData[0][3].",
  53. SWITCH =".$rowData[0][7].",
  54. node = ".$rowData[0][8].",
  55. DSLAMIP = ".$rowData[0][5].",
  56. DSLAMADI = ".$rowData[0][6].",
  57. MsanAdres = ".$rowData[0][13];
  58.  
  59. if(mysqli_query($conn,$sql)){
  60.  
  61. $exceldata[] = $rowData[0];
  62.  
  63. }else{
  64.  
  65. echo "Hata : ".$sql."<br>".mysqli_error($conn);
  66.  
  67. }
  68.  
  69. }
  70.  
  71. mysqli_close($conn);
  72.  
  73. }
  74.  
  75. ?>
  76.  
  77. <form action="" method="POST" enctype="multipart/form-data">
  78.  
  79. <input type="file" name="file">
  80. <input type="submit" name="upload" value="Upload">
  81.  
  82. </form>
Add Comment
Please, Sign In to add comment