Hi I badly need you help.
Error showing after importing .CSV file using mysql load data infile.
I have a form upload below which working fine
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
and a PHP upload script using load data infile.
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'] . ")";
}
Everything is fine, except the load data local infile cannot see the right path. please see the error: Can't find file 'logJan262013.CSV'. but the .csv file is uploaded successfully in folder 'uploads/'. Any help would be appreciated.
thanks alot!
You're using the query:
$mysql = "LOAD DATA LOCAL INFILE '".$_FILES['my-file']['name']."'...
I do believe you are wishing to use the full path
$mysql = "LOAD DATA LOCAL INFILE '".$path."'...
You do
if (move_uploaded_file($_FILES['my-file']['tmp_name'], $path)) {
before
$query = mysqli_query($link, $mysql)
So, it is not surprising, that LOAD DATA
doesn't find the file.
If you give LOAD DATA
the proper $path
, it should work as expected.
Err you haven't told the LOAD DATA INFILE the path! Try telling it the path and all should be OK.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.