Guest User

Untitled

a guest
Nov 5th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. date_sourced : date
  2. sha1: varchar(255)
  3. vsdt: varchar(255)
  4. trendx:varchar(255)
  5. notes:varchar(255)
  6.  
  7. <?php
  8. if(isset($_POST['submit'])) {
  9. $host = 'localhost';
  10. $user = 'root';
  11. $password = '';
  12. $db = 'jeremy_db';
  13. ini_set('max_execution_time', 500);
  14. $con = mysqli_connect($host,$user,$password) or die('Could not' .mysqli_error($con));
  15.  
  16. mysqli_select_db($con, $db) or die ('Could not' .mysqli_error($con));
  17.  
  18. $file = $_FILES['file']['tmp_name'];
  19. $handle = fopen($file, "r");
  20. ini_set ('memory_limit', filesize ($file) + 4000000);
  21. $c = 0;
  22.  
  23. while(($csvdata = fgetcsv($handle,10000,","))!== FALSE){
  24. $sha1 = $csvdata[0];
  25. $vsdt = $csvdata[1];
  26. $trendx = $csvdata[2];
  27.  
  28. $sql = "INSERT INTO jeremy_table_trend (sha1,vsdt,trendx) VALUES ('$sha1','$vsdt','$trendx')";
  29. $query = mysqli_query($con , $sql);
  30.  
  31. $c = $c+1;
  32. }
  33. if($query){
  34. echo '<script type="text/javascript">';
  35. echo ' alert("CSV uploaded to server");';
  36. echo ' window.location.href = "trendx.php";';
  37. echo '</script>';
  38. }
  39. else {
  40. echo "SLAM";
  41. }
  42. }
  43. ?>
  44.  
  45. <form id = "myForm" class="ui input" enctype="multipart/form-data" method = "POST" action="trend_upload_csv.php" role = "form">
  46. <input type = "file" name ="file" id="file" size = "150">
  47. <input id="myBtn" class="ui small red button" type = "submit" class = "btn btn-default" name ="submit" onclick = "myFunction();" value = "Upload CSV" disabled />
  48. </form>
Add Comment
Please, Sign In to add comment