将Excel文件导入mysql

时间:2015-07-06 08:23:26

标签: php mysql excel

我需要将excel文件上传到mysql db,我可以上传csv,但excel文件无法正常上传

这是我的代码

<?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.";
}
}
?>

1 个答案:

答案 0 :(得分:-1)

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