嗨,我非常需要你的帮助。
使用 mysql load data infile 导入 .CSV 文件后显示错误。
我在下面有一个表格上传,工作正常
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
和一个使用加载数据文件的 PHP 上传脚本。
require("../config/conn.php");
if (is_uploaded_file($_FILES['my-file']['tmp_name']) && $_FILES['my-file']['error']==0) {
$path = 'C:/xampp/htdocs/dom/test/uploads/' . $_FILES['my-file']['name'];
if (!file_exists($path)) {
if (move_uploaded_file($_FILES['my-file']['tmp_name'], $path)) {
echo $mysql = "LOAD DATA LOCAL INFILE '".$_FILES['my-file']['name']."'
REPLACE INTO TABLE table
FIELDS
TERMINATED BY ','
LINES
TERMINATED BY '\\n'
IGNORE 1 LINES
(`col1`,`col2`,`col3`,`col4`,`col5`....)";
$query = mysqli_query($link, $mysql) or die(mysqli_error($link));
if(!$query)
{
printf("Error message: %s\n", mysqli_error($link));
}
} else {
echo "The file was not uploaded successfully.";
}
} else {
echo "File already exists. Please upload another file.";
}
} else {
echo "The file was not uploaded successfully.";
echo "(Error Code:" . $_FILES['my-file']['error'] . ")";
}
一切都很好,除了加载数据本地 infile 看不到正确的路径。请查看错误:找不到文件“logJan262013.CSV”。但 .csv 文件已成功上传到文件夹“uploads/”中。任何帮助,将不胜感激。
多谢!