[英]Import Excel file in to mysql
我需要將 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.";
}
}
?>
您需要使用 PHPExcel 庫來訪問 excel 文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.