We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

how to read csv file saved in webserver using codeigniter.

Development and Programming

gglenn12's avatar
gglenn12
1 posts
12 years ago
gglenn12's avatar gglenn12

good day everyone, I start using codeigniter for 3 weeks. I’m developing a system that save csv file, the problem is i don’t know how to view the file that i save in my web server.

this is how i save/find csv file together with the file name

controller

function SaveOrFind()
 {

  $this->load->helper(array('form', 'url'));
  $this->load->model('dtr_model');
                $this->load->library('csvimport');
  
  if(isset($_POST["btnSaveAndSubmit"])){
   
   $config['upload_path'] = './uploads/';
   $config['allowed_types'] = 'csv';
   
   $this->load->library('upload', $config);
    
   $this->load->library('form_validation');
   $this->form_validation->set_rules('selTimerecordMonth', 'Month', 'required');
   $this->form_validation->set_rules('selTimerecordPeriod', 'Period','required');
  
  
    if ( !$this->upload->do_upload() || $this->form_validation->run() == FALSE)
    {
     $error = array('error' => $this->upload->display_errors());
     
     $this->load->view('header');
     $this->load->view('dtr_nav');
     $this->load->view('dtr_timerecord_nav');
     $this->load->view('dtr_timerecord_main', $error);
     $this->load->view('footer');

    }
    else
    {
     
     $image_data = $this->upload->data();          
     $insert_data = array(
      'FILENAME' => $image_data["file_name"],
      'MONTH'=>$this->input->post('selTimerecordMonth'),
      'PERIOD'=>$this->input->post('selTimerecordPeriod'));
     $query = $this->db->insert('dtr_timerecord',$insert_data);
     $id = $this->db->insert_id();
         
     
     $file_data = $this->upload->data();
              $file_path =  './uploads/'.$file_data['file_name']; 
     
     echo "[removed]alert('Upload Successful: ". $file_data['file_name']."');[removed]";
     $this->timerecord();
       
            }

          }
    if(isset($_POST["btnFind"])){
     $this->load->view('header');
     $this->load->view('dtr_nav');
     $this->load->view('dtr_timerecord_nav');
      
     $this->load->library('form_validation');
     $this->form_validation->set_rules('selTimerecordMonth', 'Month', 'required');
     $this->form_validation->set_rules('selTimerecordPeriod', 'Period','required');
   
     if ($this->form_validation->run() == FALSE)
     {
      $this->load->view('dtr_timerecord_main',array('error'=>''));
      
     }
     else
     { 
      $this->load->model('dtr_model');
      $data=array('result'=>$this->dtr_model->finddtr());     
      $this->load->view('success_dtr_find',$data);
      }
     $this->load->view('footer');
    }
 }

model

function FindDtr(){
 $getInfo = "SELECT * FROM dtr_timerecord WHERE MONTH ='".$this->input->post('selTimerecordMonth')."' AND PERIOD ='".$this->input->post('selTimerecordPeriod')."'";
        $getResult = $this->db->query($getInfo);
  return $getResult;                                      
 }

view in viewing csv file

<html>
<head>
</head>

<div id="content">
<?php
echo"<table border='1' >
 <tr>
  <th></th>
  <th>MONTH</th>
  <th>PERIOD</th>
  <th>FILE NAME</th>
  <th>ACTION</th>
 </tr>";
 foreach ($result->result_array() as $row) {
  echo "<tr>";
  echo form_open("dtr/importcsv");
  
  echo"<td><input type='hidden' name='txtTimeRecordID' value='".$row["TIME_RECORD_ID"]."'></td>".
  "<td align='center'>".$row["MONTH"]."</td>".
  "<td align='center'>".$row["PERIOD"]."</td>".
  "<td align='center'>".$row["FILENAME"]."</td>".
  "<td><input type='submit' value='VIEW'></td>";
  echo form_close();
  "</tr>";
 }
echo "</table>";
echo "
";
echo anchor('dtr/timerecord', 'BACK');
?>
</div>
</html>
       
Boyink!'s avatar
Boyink!
5,011 posts
12 years ago
Boyink!'s avatar Boyink!

You’ve posted in the ExpressionEngine forum - might want to try the CI forums…;)

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.