Advertisement
Guest User

val

a guest
Oct 17th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. <?php
  2. require "../backends/theDBConn.php";
  3.  
  4.  
  5. $output = '';
  6.  
  7. if(isset($_FILES['file']['name'][0]))
  8. {
  9.  
  10.  
  11. $fileName = $_FILES["file"]["tmp_name"];
  12. foreach($_FILES['file']['name'] as $key=>$val){
  13. $output .= $file_name = $_FILES['file']['name'][$key];
  14. $fileName = $_FILES["file"]["tmp_name"][$key];
  15.  
  16.  
  17.  
  18. // get file extension
  19. // $ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
  20.  
  21. // // get filename without extension
  22. // $filenamewithoutextension = pathinfo($file_name, PATHINFO_FILENAME);
  23.  
  24. // if (!file_exists(getcwd(). '/uploads')) {
  25. // mkdir(getcwd(). '/uploads', 0777);
  26. // }
  27.  
  28. // $filename_to_store = $filenamewithoutextension. '_' .uniqid(). '.' .$ext;
  29. // move_uploaded_file($_FILES['file']['tmp_name'][$key], getcwd(). '/uploads/'.$filename_to_store);
  30.  
  31. $file = fopen($fileName, "r");
  32. while (($column = fgetcsv($file, 10000, ",")) !== FALSE) {
  33.  
  34. // NEED
  35. $lengthArray[] = count($column);
  36. // $row ++;
  37. //
  38.  
  39. // $sql = "INSERT into userinfo (phonenumber, name, bank_name,branch_name, account_no, date_registered, enabled, status)
  40. // values ('" . $column[0] . "','" . $column[1] . "','" . $column[2] . "','" . $column[3] . "','" . $column[4] . "','" . $column[5] . "','" . $column[6] . "','" . $column[7] . "')";
  41.  
  42. $sql = "INSERT into userinfo (phonenumber,group_id,enabled)
  43. values ('" . $column[0] . "','1','1' );";
  44. // run($sql);
  45.  
  46.  
  47. // NEED
  48. $lengthArray = array_unique($lengthArray);
  49.  
  50. if (count($lengthArray) == 1) {
  51. $response = array(
  52. "type" => "success",
  53. "message" => "File Validation Success."
  54. );
  55.  
  56. $msg = "SUCCESS";
  57.  
  58. } else {
  59. $response = array(
  60. "type" => "error",
  61. "message" => "Invalid CSV: Count mismatch."
  62. );
  63.  
  64. $msg = "FAILED";
  65. }
  66.  
  67.  
  68. }
  69. // $output .= "<div>".$val."</div>";
  70.  
  71. }
  72. }
  73. echo "File(s) uploaded successfully";
  74. echo $output;
  75.  
  76. die;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement