PHP MySQL - Import CSV Using LOAD DATA INFILE - Determine file path? -


i need connecting dots on this. there's plenty of snippets floating around haven't found end end tutorial.

for simple custom cms i'm building want option end user admins upload csv of other users. phpmyadmin or other "direct" access db not option environment. i'm trying build file upload form inserts data in appropriate table.

i found this tutorial on building upload form - working fine (although i'd add additional validation/security). , based on these several posts here (like one) think using load data infile makes more sense trying loop , parse fgetcsv or (but feel free disagree).

here's current code - it's not working , assume it's file path - how should format it? _uploads directory in same place processor file.

$target_path = "_uploads/";  $target_path = $target_path . basename( $_files['uploadedfile']['name']);   if(move_uploaded_file($_files['uploadedfile']['tmp_name'], $target_path)) {     echo "the file ".  basename( $_files['uploadedfile']['name']).      " has been uploaded " . $target_path; } else{     echo "there error uploading file, please try again!"; }  $sql = "load data infile $target_path         table user         (userfirstname, userlastname)         fields terminated ',' enclosed '\"' escaped '\"'         lines terminated '\r\n'         ";  $result = mysql_query($sql, $connection);  if (mysql_affected_rows() == 1) {     $message = "the user updated!"; } else {     $message = "the user update failed: ";     $message .= mysql_error();  }  echo $message; 

any suggestions or pointers decent tutorials appreciated.

your problem php working on webserver, mysql working on database server. think long no replication involved missing "dot"

load data local infile 

to read client-computer.

http://dev.mysql.com/doc/refman/5.1/de/load-data.html


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -