Page 1 of 1

Can not open file using LOAD DATA INFILE

Posted: Fri Aug 05, 2011 5:33 pm
by edziffel
Trying to upload from a temp directory uploaded using $_POST $_FILES for what ever reason I'm getting the following error message:
Can't get stat of '/var/lib/mysql/temp_uploads/tester_feet_CVS.cvs' (Errcode: 2)
the code on that page is the following:

Code: Select all

<!DOCTYPE html>
<?php session_start();?>
<html>
<head>
<meta charset="utf-8" />
<title><?php echo $title; ?></title>
</head>
<body>

<?php 
echo $_SESSION['target_path']."<br/>".$_SESSION['database_selected']."<br/>".$_SESSION['database_table_selected']."<br/>"."<br/>";
?>
<?php $result = mysql_connect('localhost','root','qwerty123');
if($result) {
	echo "you are connected"."<br/>";
	}
	else {
	echo "you are not connected". mysql_error();
	}
?>
<?php

mysql_select_db("".$_SESSION['database_selected']."");
$result = mysql_query("SELECT * FROM  ".$_SESSION['database_table_selected']."");
if (!$result) {
    die('Query failed: ' . mysql_error());
    }
    else {
    echo "you have selected a database and table"."<br/>";
}
?>
<?php
echo getcwd()."<br/>";
$uploadalready="LOAD DATA INFILE 'temp_uploads/tester_feet_CVS.cvs' INTO TABLE TESTER_FEET FIELDS TERMINATED BY ','";

mysql_query($uploadalready) or die(mysql_error());

?>

</body>
</html>
for which the output to the web page is:
[text]

temp_uploads/tester_feet_CVS.csv
drawback
TESTER_FEET

you are connected
you have selected a database and table
/var/www/drawback.com
Can't get stat of '/var/lib/mysql/temp_uploads/tester_feet_CVS.cvs' (Errcode: 2)
[/text]

Made the temp_uploads file myself and gave it 777 privilages. can browse to the uploaded file no problem.

Anyone know what is going on here?

Re: Can not open file using LOAD DATA INFILE

Posted: Fri Aug 05, 2011 6:27 pm
by twinedev
Just a quick guess here, but it is most likely that you are not giving the full path to the .csv file, you are giving it relative to the script that is running, but SQL doesn't know where the script is running from, so you need to give it the FULL path.

-Greg