Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function do_upload()
- {
- $csv_path = realpath(APPPATH . '/../assets/uploads/CSV/');
- $config['upload_path'] = $csv_path;
- $config['allowed_types'] = '*'; // All types of files allowed
- $config['overwrite'] = true; // Overwrites the existing file
- $this->upload->initialize($config);
- $this->load->library('upload', $config);
- if ( ! $this->upload->do_upload('userfile'))
- {
- $error = array('error' => $this->upload->display_errors());
- $this->layout->buffer('content', 'program/upload', $error);
- $this->layout->render();
- }
- else
- {
- //$csv_upload = array('upload_data' => $this->upload->data());
- $image_data = $this->upload->data();
- $fname = $image_data['file_name'];
- $fpath = $image_data['file_path'].$fname;
- $fh = fopen($fpath, "r");
- if (!empty($fh)) {
- $insert_str = 'INSERT INTO wc_program (`JobRef`, `Area`, `Parish`, `AbbrWorkType`, `WorkType`, `Timing`, `TrafficManagement`, `Location`, `Duration`, `Start`, `Finish`)
- VALUES '."\n";
- // Create each set of values.
- while (($csv_row = fgetcsv($fh, 2000, ',')) !== false) {
- foreach ($csv_row as &$row) {
- $row = strtr($row, array("'" => "\'", '"' => '\"'));
- }
- $insert_str .= '("'
- // Implode the array and fix pesky apostrophes.
- .implode('","', $csv_row)
- .'"),'."\n";
- }
- // Remove the trailing comma.
- $insert_str = rtrim($insert_str, ",\n");
- // Insert all of the values at once.
- $this->db->set($insert_str);
- var_dump($csv_row);
- //$this->layout->set('title','Uploaded File Successfully');
- //$this->layout->buffer('content', 'program/success');
- //$this->layout->render();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement