我使用以下代码上传php mysql中的csv文件:
en<?php
session_start();
if(!isset($_SESSION["UID"]))
{
header("Location: index.php");
}
if(isset($_POST["import"]))
{
//First we need to make a connection with the database
$host='localhost'; // Host Name.
$db_user= 'root'; //User Name
$db_password= '';
$db= 'crm_6feb'; // Database Name.
$conn=mysqli_connect($host,$db_user,$db_password) or die("unable to connect to database");
echo $filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
//$sql_data = "SELECT * FROM prod_list_1 ";
$count = 0;
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
//print_r($emapData);
//exit();
$count++;
if($count>1){
echo $sql = "insert into enquiry(en_name,en_mobile,en_landline,en_email,en_address,salesid,date_recieved,duplicate,date_add,ip) values ('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]',$emapData[5],$emapData[6],'$emapData[7]',$emapData[8],'$emapData[9]')";
$RES = mysqli_query($conn, $sql) or die("error in insert");
}
}
fclose($file);
echo 'CSV File has been successfully Imported';
header('Location: importleads.php');
}
else
echo 'Invalid File:Please Upload CSV File';
}?>
<!DOCTYPE html>
<html>
<head>
<title>Add Order Status</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<?php include("includes/header.php");?>
<div class="box">
<h2>Add Order Status</h2>
<div class="display">
<form enctype="multipart/form-data" method="post" role="form">
<div class="form-group">
<label for="exampleInputFile">File Upload</label>
<input type="file" name="file" id="file" size="150">
<p class="help-block">Only Excel/CSV File Import.</p>
</div>
<button type="submit" class="btn btn-default" name="import" value="import">Upload</button>
</form>
</div></div></body></html>
现在,点击上传按钮后,我收到以下消息为错误:
插入中的C:\ wamp \ tmp \ phpBEC.tmp错误
excel内容如下:
Name| Mobile| Alternate Number|Email| Address| Sales id| Date Rec| Dupli|Date Add| Ip
请建议我做错事。
等待恢复你的帮助。