0

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

Robert
  • 5,484
  • 1
  • 22
  • 35
black
  • 729
  • 5
  • 13
  • 28

2 Answers2

2

Just Add LOCAL before INFILE in your Query

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

1

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.

Robert
  • 5,484
  • 1
  • 22
  • 35
  • that worked man !! csv uploaded in server location but the 1st value from csv file is not showing in browser as it should . i think its a permission issue that case because the group apache has only Read only permission ? thanks anyway Cheers!! – black Apr 30 '15 at 09:10
  • Make another question on SO pls with the code, as these are two different questions. – Robert Apr 30 '15 at 09:11