Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "hello";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- echo "connected";
- use BoxSpoutReaderReaderFactory;
- use BoxSpoutCommonType;
- // Include Spout library
- include ('spout-2.4.3srcSpoutAutoloaderautoload.php');
- // check file name is not empty
- if (!empty($_FILES['file']['name'])) {
- // Get File extension eg. 'xlsx' to check file is excel sheet
- $pathinfo = pathinfo($_FILES["file"]["name"]);
- // check file has extension xlsx, xls and also check
- // file is not empty
- if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
- && $_FILES['file']['size'] > 0 ) {
- // Temporary file name
- $inputFileName = $_FILES['file']['tmp_name'];
- // Read excel file by using ReadFactory object.
- $reader = ReaderFactory::create(Type::XLSX);
- // Open file
- $reader->open($inputFileName);
- $count = 1;
- $rows = array();
- // Number of sheet in excel file
- foreach ($reader->getSheetIterator() as $sheet) {
- // Number of Rows in Excel sheet
- foreach ($sheet->getRowIterator() as $row) {
- // It reads data after header. In the my excel sheet,
- // header is in the first row.
- if ($count> 1){
- $newDate = $row[4]-> format('d/m/Y');
- $result=mysqli_query($conn,"INSERT INTO stud VALUES ('NULL','$row[1]','$row[2]','$row[3]','$newDate','$row[5]','$row[6]','$row[7]')");
- }
- $count++;
- }
- }
- // Close excel file
- $reader->close();
- } else {
- echo "Please Select Valid Excel File";
- }
- } else {
- echo "Please Select Excel File";
- }
- ?>
- $newDate = $row[4]-> format('d/m/Y');
- $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