Search code examples
phpmysqlapachemysql-loadfile

Cant get stat of 'var/lib/mysql/ (Errcode:2)


this code with the path works fine for me in 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);

now when i run in centos server i give path like

$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)

now when i use LOAD DATA LOCAL INFILE 'var/www/html/tool it is giving

cant find file 'var/www/html/file.scv

my web root folder is in /var/www/html/tool and i access this via xxx.xxx.xx.xx/tool

everytime a csv file is uploaded in server location /var/www/html/tool with OWNER as apache-Apache having Read and Write

Group as apache having only Read Only permisssion

i tried like chmod 777 -R /var/www/html/tool but the file is still uploading in apache as group and apache-Apache as Owner

Yes I have seen the other post simillar to this and used LOAD DATA LOCAL INFILE Plz Suggest


Solution

  • You are using var/www/html/tool/ as a path and not /var/www/html/tool/, thus the path is relative to the mysql directory in /var/lib/mysql. Just add another slash at the front.