upload csv file and save data in data base in cakephp 3
<p>How can i upload csv file and save data in to my mysql database.
according to id.in cakephp 3
i am unable to do that. can any one help me.
my controller
    public function import() {</p>

<pre><code>    if(isset($_POST["submit"])){
        if($_FILES['file']['csv']){
            $filename = explode('.', $_FILES['file']['csv']);
            debug($filename);
            if($filename[1]=='csv'){
                $handle = fopen($_FILES['file']['csv'], "r");
                while ($data = fgetcsv($handle)){
                    $item1 = $data[0];
                  //  $item2 = $data[1];
                  //  $item3 = $data[2];
                  //  $item4 = $data[3];
                    $Applicants = $this-&gt;Applicants-&gt;patchEntity($Applicants, $item1);
                    $this-&gt;Applicants-&gt;save($Applicants);
                }
                fclose($handle);
            }
        }
    }
    $this-&gt;render(FALSE);
}
</code></pre>

<p>my view:</p>

<pre><code>&lt;div class="col-md-8"&gt;
        &lt;?= $this-&gt;Form-&gt;create('Applicants',['type' =&gt; 'file','url' =&gt; ['controller'=&gt;'Applicants','action' =&gt; 'import'],'class'=&gt;'form-inline','role'=&gt;'form',]) ?&gt;
        &lt;div class="form-group"&gt;
            &lt;label class="sr-only" for="csv"&gt; CSV &lt;/label&gt;
            &lt;?php echo $this-&gt;Form-&gt;input('csv', ['type'=&gt;'file','class' =&gt; 'form-control', 'label' =&gt; false, 'placeholder' =&gt; 'csv upload',]); ?&gt;
        &lt;/div&gt;
        &lt;button type="submit" class="btn btn-default"&gt; Upload &lt;/button&gt;
    &lt;?= $this-&gt;Form-&gt;end() ?&gt;
&lt;/div&gt;
</code></pre>