phpcodeignitercsv-import

CodeIgniter version 3.1.11 - How to post csv file in codeigniter?


I am new at codeigniter, i want to post csv file using this input method $this->input->post(). I am using fopen() funtion of php for read csv file, it required file name and path in parameter.

this is my html simple html file.

<form method="post" class="form" action="<?php echo base_url('csv/store'); ?>" enctype="multipart/form-data">
    <label for="myfile">Select a file:</label>
    <input type="file" id="myfile" name="myfile" accept=".csv">
    <input type="text" id="name" name="name">
    <br />
    <input type="submit" class="submit" value="Submit"/>
</form>

and this is my controller

public function store() {
        $x = $this->input->post('myfile');
        $y = $this->input->post('name');
        print_r($x);
        print_r($y);
        exit;      
}

if i print $x it not getting output but if i print $y it is getting output.


Solution

  • csv is a file... so, use print_r($_FILES);