1

This is view

 <form method="post" action = "<?php echo site_url('Welcome/csvfile');?>" 
 enctype="multipart/form-data">
 <input type="file" name="csvfileread" required accept=".csv,.xlsx">
 <input type="submit" name="submit">
 </form>

This is my controller

public function csvfile()
{   
    $this->load->library('CSVReader');

    if(isset($_POST["submit"]))
    {
        $csv = $_FILES['csvfileread']['tmp_name'];

        $opencsv = fopen($csv,"r");
        while (($row = fgetcsv($opencsv, 10000, ",")) != FALSE) 
        {
            print_r($row); 

            $sql = "INSERT into data (id,name) VALUES('', '".addslashes($row[0])."')  ";
            $this->db->query($sql);
        }
    }
}

Data gets inserted but then it is encrypted how to put parsed data in database? My excel sheet contains 25 rows...how to access data of those rows? and insert accordingly in database...the database above is dummy database.

output of $row

     Array ( [0] => PK!������[Content_Types].xml 
     ��(��T�n�0�W�?D�V�@���8t9�H�0�@ [1] => 
      �����PP��H4zI��o�g'�mYDh�M� �l洱 
     �T��^z�"BRV��YH�P�G�W�l�#^m19���J���`��R? 
     ���*s�D��$��%��襤�`�)qm��.��c�uy� � ������O  
     /�c)�wڇ��b� 
     ��PK!K�_qxl/workbook.xml�R�N�0}7���K�� 
     l$F����z��vi����vd����=�g��n�<6�| 
     �u��ƣ�ХR�r��~��R�<ׂ+�!�'ptY�� [1] => :c��� )
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Just Converted .xlsx file to .csv file.