0

这个带有路径的代码在本地主机中对我来说很好

$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/toolOWNER as apache-ApacheRead and Write

Group as apache having only Read Only permisssion

apache as group我试过像 chmod 777 -R /var/www/html / tool 但文件仍在上传apache-Apache as Owner

是的,我看过与此类似的另一篇文章并使用了LOAD DATA LOCAL INFILE 请建议

4

2 回答 2

2

只需LOCAL在查询中的 INFILE 之前添加

$sql = LOAD DATA LOCAL INFILE 'C://xampp/htdocs/xampp/www/tool/"

于 2020-11-26T08:22:46.400 回答
1

您使用var/www/html/tool/的是路径而不是/var/www/html/tool/,因此该路径是相对于/var/lib/mysql. 只需在前面添加另一个斜线。

于 2015-04-30T09:01:40.280 回答