Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.87 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <?php
  6. $con = mysqli_connect("localhost","root","","DBName");
  7.  
  8. if ($_FILES['csv']['size'] > 0) {
  9.  
  10.         //get the csv file
  11.         $file = $_FILES['csv']['name'];
  12.         $handle = fopen($file,"r");
  13.        
  14.         $file_type = pathinfo($file,PATHINFO_EXTENSION);
  15.        
  16.         //loop through the csv file and insert into database
  17.         while ($data = fgetcsv($handle,1000,",")) {
  18.             if ($data[0]) {
  19.                 mysqli_query($con, "INSERT INTO users (username, first_name, last_name) VALUES
  20.                     (
  21.                         '".addslashes       ($data[0])."',  
  22.                         '".addslashes       ($data[1])."',
  23.                         '".addslashes       ($data[2])."'
  24.                     )
  25.                 ");
  26.                
  27.             }
  28.            
  29.         }  
  30.         exit;
  31. }
  32. ?>
  33.  
  34. <form action="" method="post" enctype="multipart/form-data">
  35.         <input type="file" name="file" /><br />
  36.         <input type="submit" name="submit" value="Submit" />
  37. </form>
  38.  
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement