Can not open file using LOAD DATA INFILE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
edziffel
Forum Newbie
Posts: 9
Joined: Wed Jul 13, 2011 6:32 am

Can not open file using LOAD DATA INFILE

Post 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?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Can not open file using LOAD DATA INFILE

Post 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
Post Reply