带有路径的代码在localhost中可以正常使用
$sql = "LOAD DATA INFILE 'C://xampp/htdocs/xampp/www/tool/".@mysql_escape_string($this->file_name).
"' INTO TABLE `".$this->table_name.
"` FIELDS TERMINATED BY '".@mysql_escape_string($this->field_separate_char).
"' OPTIONALLY ENCLOSED BY '".@mysql_escape_string($this->field_enclose_char).
"' ESCAPED BY '".@mysql_escape_string($this->field_escape_char).
"' LINES TERMINATED BY '" .@mysql_escape_string("\r\n") . "' ".
($this->use_csv_header ? " IGNORE 1 LINES " : "")
."(`".implode("`,`", $this->arr_csv_columns)."`)";
//echo $sql;
mysqli_query(DB::cxn(),$sql) or die("Import Error: " . mysqli_error(DB::cxn()));
// Delete the file now it's been imported
unlink("C:/xampp/htdocs/xampp/www/tool/". $this->file_name);
现在当我在centos服务器上运行时,我会给出像
这样的路径$sql = "LOAD DATA INFILE 'var/www/html/tool/".@mysql_escape_string($this->file_name).
unlink("var/www/html/tool/". $this->file_name);
Cant get stat of 'var/lib/mysql/var/www/html/tool/file.csv (Errcode:2)
现在,当我使用LOAD DATA LOCAL INFILE
'var/www/html/tool
时,它正在提供
cant find file 'var/www/html/file.scv
我的网络根文件夹位于/var/www/html/tool
,我通过xxx.xxx.xx.xx/tool
每次csv文件上传到服务器位置/var/www/html/tool
,OWNER as apache-Apache
Read and Write
Group as apache having only Read Only permisssion
我尝试过像chmod 777 -R / var / www / html / tool,但文件仍在apache as group
和apache-Apache as Owner
是的我已经看过另一篇文章,并使用了LOAD DATA LOCAL INFILE
Plz建议
答案 0 :(得分:1)
您使用var/www/html/tool/
作为路径,而不是/var/www/html/tool/
,因此路径相对于/var/lib/mysql
中的mysql目录。只需在前面添加另一个斜杠。
答案 1 :(得分:1)
只需在查询中的INFILE之前添加LOCAL
$sql = LOAD DATA LOCAL INFILE 'C://xampp/htdocs/xampp/www/tool/"