I am trying to create a webpage using php which uploads excel file on the page using browse button and imports it into mysql database.
I am able to upload csv file and import it in database
//html code
<form action="import.php" enctype="multipart/form-data" method="post"
role="form">
<input type="file" name="file" id="file" accept=".xls">
<br><br>
<input type="submit" name="submit" value="submit">
//php code
 if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
 } 
 echo nl2br("Connected to Database successfully \n");
 mysqli_query($conn,'Truncate table sheet');
 $file = $_FILES['file']['tmp_name'];
 file_put_contents($file,str_replace("'","\'",file_get_contents($file)));
 $handle = fopen($file,"r");
// another part of code
 if($sql) {
     $ffilename=basename($_FILES['file']['name']);
     $filename=preg_replace('/\\.csv/',' ',$ffilename);
     echo "File ".$filename." imported in database";
 } 
I want to upload excel file and convert it to csv without pressing any extra button and use the same code for csv file which i have been using , i.e csv file while will be imported but excel file will be uploaded.
 
     
    

