title: Cannot import xls/xlsx files
body: <p>I am importing an excel file into MySQL using PHP. The following code works for csv files but not for xls/xlsx file formats.</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Import Excel to MySQL using PHP &lt;/title&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
    &lt;/head&gt;
    &lt;body style="padding-top:50px;"&gt;
  
  &lt;div class="container"&gt;&lt;!-- container class is used to centered  the body of the browser with some decent width--&gt;
      &lt;div class="row"&gt;&lt;!-- row class is used for grid system in Bootstrap--&gt;
          &lt;div class="col-md-4 col-md-offset-4"&gt;&lt;!--col-md-4 is used to create the no of colums in the grid also use for medimum and large devices--&gt;
              &lt;div class="login-panel panel panel-success"&gt;
                  &lt;div class="panel-heading"&gt;
                      &lt;h3 class="panel-title"&gt;Import here&lt;/h3&gt;
                  &lt;/div&gt;
                  &lt;div class="panel-body"&gt;
  
                      &lt;form method="post" action="import.php" enctype="multipart/form-data"&gt;
                          &lt;fieldset&gt;
                              &lt;div class="form-group"&gt;
                                &lt;input type="file" name="file"/&gt;
                              &lt;/div&gt;
                          &lt;input class="btn btn-success" type="submit" name="submit_file" value="Submit"/&gt;
                          &lt;/fieldset&gt;
                      &lt;/form&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Import.php</strong></p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', TRUE);
  ini_set('display_startup_errors', TRUE);
  /*
  Developer: Ehtesham Mehmood
  Site:      PHPCodify.com
  Script:    Import Excel to MySQL using PHP and Bootstrap
  File:      import.php
  */
  
  // Including database connections
  require_once 'db_con.php';
  
  if(isset($_POST["submit_file"]))
  {
   $file = $_FILES["file"]["tmp_name"];
  
   $file_open = fopen($file,"r");
   while(($csv = fgetcsv($file_open, 1000, ",")) !== false)
   {
    $employee_name = $csv[0];
    $employee_designation = $csv[1];
    $employee_salary = $csv[2];
  
    $stmt = $DBcon-&gt;prepare("INSERT INTO employee(employee_name,employee_designation,employee_salary) VALUES(:employee_name,:employee_designation,:employee_salary)");
  
    $stmt-&gt;bindparam(':employee_name', $employee_name);
    $stmt-&gt;bindparam(':employee_designation', $employee_designation);
    $stmt-&gt;bindparam(':employee_salary', $employee_salary);
    $stmt-&gt;execute();
   }
  }
  
  echo "Imported Successfully";
  ?&gt;
  </code></pre>