· 8 years ago · Feb 12, 2018, 06:06 PM
1<div class="form-group col-lg-12 col-xs-12">
2
3 <div class="row" id="excle_file_section">
4 <div class="form-group col-lg-12 col-xs-12">
5 <label for="usr">Select excle (CSV) file:</label>
6 <input type="file" name="csvFile" accept=".csv" class="form-control" id="usr" required="">
7 </div>
8 </div>
9 </div>
10
11function insertBlock()
12{
13 try{
14
15 $filename=$_FILES["csvFile"]["tmp_name"];
16 $Date = $this->input->post('date');
17 $Start_time = $this->input->post('exam_start_time');
18 $End_time = $this->input->post('exam_end_time');
19 $Subject = $this->input->post('exam_paper');
20 $Shift_Name = $this->input->post('shift_name');
21
22 $table = $Date.$Shift_Name;
23 //$this->db->insert('exam_scheduler', $this);
24 $sql = "CREATE TABLE IF NOT EXISTS `$table` (Id INT PRIMARY KEY AUTO_INCREMENT, Hall_Ticket_No VARCHAR(200) NULL,Name VARCHAR(200) NULL,Course VARCHAR(200) NULL);";
25 $this->db->query($sql);
26
27
28 if($_FILES["csvFile"]["size"] > 0)
29 {
30 $file = fopen($filename, "r");
31 while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
32 {
33
34 $sql = "INSERT into $table (Hall_Ticket_No,Name,Course)values ('".$getData[0]."','".$getData[1]."','".$getData[2]."')";
35 $this->db->query($sql);
36 }
37 fclose($file);
38 }
39
40 }catch(Exception $e){
41 echo 'Message: ' .$e->getMessage();
42 }
43
44 $data = array('content'=>'view_block');
45 $this->load->view('template_master',$data);
46}