php - CSV upload works with local WAMP but not with remote LAMP using LOAD DATA -


new:

uploading actual .csv file /tmp folder using winscp correct structure server , running load data local infile mysql cli works flawlessly. if upload form trigger "sorry" error. i've echo'ed , var_dumped several global $_file variables , here results:

$_files['csv']['tmp_name']:

dirname /tmp

basename php8k4jfn (different every-time run script , has not .csv ending)

filename php8k4jfn

full filepath:

/tmp/php8k4jfn

$_files['csv']['error']:

0

permissions:

mysql , www-data part of root group , both allowed read/write /tmp

executing load data infile local... mysql cli mycsv.csv file inside /tmp work fine although warnings(could trigger error?).

removed apparmor , gave root 1775 permission t /tmp


my form lets upload csv file.

i use load data local infile upload csv's contents mysql table. idea is: user uploads local csv on computer remote lamp server using form.

if test in local environment(wamp running on computer) works correctly. i've ironed out syntax, logic , csv structure errors.

as upload entire source remote lamp server , try upload csv laptop trigger custom error: "sorry, couldn't upload csv".

i tested , don't error locally ever. later, had found out had enable local-infile inside my.cnf under [mysqld] , [mysql] on lamp server let me use local keyword.

before made change used get: the used command not allowed mysql version.

i tried echo query in php script , execute manually through mysql command line , got following error(which makes sense since temp file doesn't exist anymore): error 2 (hy000): file '/tmp/phpinuea0' not found (errcode: 2)

echo'ed query:

load data local infile '/tmp/phpinuea0'  table mydb.suites fields terminated ','  optionally enclosed '\"'  lines terminated '\n'  ignore 1 lines  (suite, business_name, business_phone, business_email)  set location_id = 2  

then tried debug form php's echo, var_dump , print_r got empty/false returns 3 statements:

$query_add_suite_csv = $this->db_connection->query($query);  echo $query_add_suite_csv;          // returns nothing var_dump($query_add_suite_csv);     // returns boolean false print_r($query_add_suite_csv);      // return nothing  if ($query_add_suite_csv) {     // success message }else{     echo "sorry, couldn't upload csv" } 

currently out of ideas why happening. in case matters, i've used this guide setup remote lamp server.

file upload php function:

private function addsuitecsv() {     if (empty($_post['suite_location_csv'])) {         $this->errors[] = "must select location of suite";     }else{          // create database connection         $this->db_connection = new mysqli(db_host, db_user, db_pass, db_name);          if (!$this->db_connection->set_charset("utf8")) {             $this->errors[] = $this->db_connection->error;         }          if (!$this->db_connection->connect_errno) {             $suite_location_csv = $this->db_connection->real_escape_string(strip_tags($_post['suite_location_csv'], ent_quotes));             if ($_files['csv']['size'] > 0) {                 $file = addslashes($_files['csv']['tmp_name']);                  $query =<<<eof                     load data local infile '$file'                     table mydb.suites                     fields terminated ','                      optionally enclosed '\"'                     lines terminated '\n'                     ignore 1 lines                     (suite, business_name, business_phone, business_email)                     set location_id = $suite_location_csv eof;                  $query_add_suite_csv = $this->db_connection->query($query);                  if ($query_add_suite_csv) {                     // success                 } else {                     // sorry                 }                             }else{                 // empty file             }         }else{             // db connection error         }     } } } 

had move production wamp instead of lamp. must have been unknown me permission issue linux.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -