Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. if (Input::hasFile('file')) {
  2. ini_set('memory_limit', '1024M');
  3. $f = Input::file('file');
  4. $bulkdata = [];
  5. $handle = fopen("$f", "r") or die("Couldn't get handle");
  6. if ($handle) {
  7. $i = 1;
  8. while (!feof($handle)) {
  9. $buffer = fgets($handle);
  10. if ($buffer[0] != '#') {
  11. $carry1 = preg_split("~\s+~", $buffer);
  12. /*echo '<pre>';
  13. print_r(sizeof($carry1));*/
  14. if (sizeof($carry1) == 5) {
  15. $data = [
  16. 'user_id' => Auth::id(),
  17. 'snp' => $carry1[0],
  18. 'chromosome' => $carry1[1],
  19. 'position' => $carry1[2],
  20. 'genotype' => $carry1[3],
  21. "created_at"=> Carbon::now(),
  22. "updated_at"=> Carbon::now()
  23. ];
  24. $i++;
  25. array_push($bulkdata, $data);
  26. }
  27. }
  28.  
  29. }
  30. /* echo '<pre>';
  31. print_r($bulkdata);*/
  32. fclose($handle);
  33. $insert_data = collect($bulkdata); // Make a collection to use the chunk method
  34. $chunks = $insert_data->chunk(1000);
  35. foreach ($chunks as $chunk) {
  36. Dnaupload::insert($chunk->toArray());
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement