How to add template in codeigniter |how to create template in codeigniter| template in codeigniter 4
csv file upload bulk record
Now a days every ecommerce site want to upload bulk product in their site ,then you have to use csv file for uploading bulk data.So first of all create input file in html.
<table width="600"> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data"> <tr> <td width="20%">Select file</td> <td width="80%"><input type="file" name="file" id="file" /></td> </tr> <tr> <td>Submit</td> <td><input type="submit" name="submit" /></td> </tr> </form> </table>
Then in server side script use the following code for getting the csv data.
$file=$_FILES["file"]["tmp_name"]; $row = 1; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "$num fields in line $row:\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "\n"; } } fclose($handle); }
Related posts