Advertisement
Guest User

Untitled

a guest
Apr 7th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public function do_upload()
  2. {
  3. $csv_path = realpath(APPPATH . '/../assets/uploads/CSV/');
  4. $config['upload_path'] = $csv_path;
  5. $config['allowed_types'] = '*'; // All types of files allowed
  6. $config['overwrite'] = true; // Overwrites the existing file
  7.  
  8. $this->upload->initialize($config);
  9. $this->load->library('upload', $config);
  10.  
  11. if ( ! $this->upload->do_upload('userfile'))
  12. {
  13. $error = array('error' => $this->upload->display_errors());
  14.  
  15. $this->layout->buffer('content', 'program/upload', $error);
  16. $this->layout->render();
  17. }
  18. else
  19. {
  20. //$csv_upload = array('upload_data' => $this->upload->data());
  21.  
  22. $image_data = $this->upload->data();
  23. $fname = $image_data['file_name'];
  24. $fpath = $image_data['file_path'].$fname;
  25. $fh = fopen($fpath, "r");
  26.  
  27.  
  28. if (!empty($fh)) {
  29.  
  30. $insert_str = 'INSERT INTO wc_program (`JobRef`, `Area`, `Parish`, `AbbrWorkType`, `WorkType`, `Timing`, `TrafficManagement`, `Location`, `Duration`, `Start`, `Finish`)
  31. VALUES '."\n";
  32.  
  33. // Create each set of values.
  34. while (($csv_row = fgetcsv($fh, 2000, ',')) !== false) {
  35.  
  36. foreach ($csv_row as &$row) {
  37. $row = strtr($row, array("'" => "\'", '"' => '\"'));
  38. }
  39.  
  40. $insert_str .= '("'
  41. // Implode the array and fix pesky apostrophes.
  42. .implode('","', $csv_row)
  43. .'"),'."\n";
  44. }
  45.  
  46. // Remove the trailing comma.
  47. $insert_str = rtrim($insert_str, ",\n");
  48.  
  49. // Insert all of the values at once.
  50. $this->db->set($insert_str);
  51. var_dump($csv_row);
  52.  
  53. //$this->layout->set('title','Uploaded File Successfully');
  54. //$this->layout->buffer('content', 'program/success');
  55. //$this->layout->render();
  56.  
  57.  
  58. }
  59.  
  60.  
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement