简体   繁体   中英

Import Excel file in to mysql

I need to upload excel file in to mysql db, i can upload csv, but excel file not uploading properly

here is my code

<?php
include ("connection.php");
if(isset($_POST["submit"]))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
while (($emapData = fgetcsv($handle, 10000, ",")) !== FALSE)
{
$c++;                                
if($c>1){                                 
$sql = "INSERT into `table`(`name`,`email`) values('$emapData[0]','$emapData[1]')";
mysql_query($sql);
}                                             
}
if($sql){
echo "You database has imported successfully. You have inserted ". $c ."     recoreds";
}else{
echo "Sorry! There is some problem.";
}
}
?>

您需要使用 PHPExcel 库来访问 excel 文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM