Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "hello";
  7.  
  8. // Create connection
  9.  
  10. $conn = mysqli_connect($servername, $username, $password, $dbname);
  11. // Check connection
  12. if (!$conn) {
  13. die("Connection failed: " . mysqli_connect_error());
  14. }
  15.  
  16. echo "connected";
  17.  
  18. use BoxSpoutReaderReaderFactory;
  19. use BoxSpoutCommonType;
  20.  
  21. // Include Spout library
  22. include ('spout-2.4.3srcSpoutAutoloaderautoload.php');
  23.  
  24. // check file name is not empty
  25. if (!empty($_FILES['file']['name'])) {
  26.  
  27. // Get File extension eg. 'xlsx' to check file is excel sheet
  28. $pathinfo = pathinfo($_FILES["file"]["name"]);
  29.  
  30. // check file has extension xlsx, xls and also check
  31. // file is not empty
  32. if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
  33. && $_FILES['file']['size'] > 0 ) {
  34.  
  35. // Temporary file name
  36. $inputFileName = $_FILES['file']['tmp_name'];
  37.  
  38. // Read excel file by using ReadFactory object.
  39. $reader = ReaderFactory::create(Type::XLSX);
  40.  
  41. // Open file
  42. $reader->open($inputFileName);
  43. $count = 1;
  44. $rows = array();
  45.  
  46. // Number of sheet in excel file
  47. foreach ($reader->getSheetIterator() as $sheet) {
  48.  
  49. // Number of Rows in Excel sheet
  50. foreach ($sheet->getRowIterator() as $row) {
  51.  
  52. // It reads data after header. In the my excel sheet,
  53. // header is in the first row.
  54. if ($count> 1){
  55.  
  56. $newDate = $row[4]-> format('d/m/Y');
  57.  
  58. $result=mysqli_query($conn,"INSERT INTO stud VALUES ('NULL','$row[1]','$row[2]','$row[3]','$newDate','$row[5]','$row[6]','$row[7]')");
  59.  
  60. }
  61. $count++;
  62. }
  63.  
  64.  
  65. }
  66.  
  67. // Close excel file
  68. $reader->close();
  69.  
  70. } else {
  71.  
  72. echo "Please Select Valid Excel File";
  73. }
  74.  
  75. } else {
  76.  
  77. echo "Please Select Excel File";
  78.  
  79. }
  80. ?>
  81.  
  82. $newDate = $row[4]-> format('d/m/Y');
  83. $result=mysqli_query($conn,"INSERT INTO stud VALUES ('NULL','$row[1]','$row[2]','$row[3]','$newDate','$row[5]','$row[6]','$row[7]')");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement