当我上传.csv文件时,加载数据infile查询无效。
我的PHP代码是:
include "../../connection.php";
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
echo '<br>';
$a = $_FILES["file"]["tmp_name"];
$csv_file = str_replace("\\", "/", "$a");
echo $csv_file;
echo '<br>';
$query = "LOAD DATA INFILE '$csv_file' INTO TABLE `competency_questions` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'";
$s = mysql_query($query);
if ($s) {
echo "<script>alert('Record successfully uploaded.');window.location.href='../../view all test.php?id=$cid';</script>";
} else {
echo 'Failed';
}
}
它显示失败错误。
有人帮我解决这个问题吗?