[eluser]Unknown[/eluser]
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
Code:
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');
}
}
controller selecting csv file by primary key
Code:
function importcsv() {
$sql = "SELECT * FROM dtr_timerecord WHERE TIME_RECORD_ID='".$this->input->post('txtTimeRecordID')."'";
?>
[removed]alert("<?php echo $sql;?>");[removed]
<?php
return $this->db->query($sql);
model in choosing csv file by primary key
Code:
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
Code:
<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 "<br>";
echo anchor('dtr/timerecord', 'BACK');
?>
</div>
</html>
i want that when i click the view button the content of the csv file ill be display in the screen