I have a three-part question: fgetcsv is better than str_getcsv , and is there a way to allow .csv file types to be displayed in the file download dialog? In the latter case, I need to use ini_set ('auto_detect_line_endings', true)
<?php if(isset($_POST['submit'])) { //$filename=$_POST['filename']; $filename = file_get_contents($_FILES['uploadedfile']['tmp_name']); $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { $import="INSERT into kmmb_member1(no_ahli,no_pin,nama,no_ic_baru,no_ic_lama) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; } else { print "<form action='import.php' method='post'>"; print "Type file name to import:<br />"; // print "<input type='text' name='filename' size='20' /><br />"; print "Select csv file: <input name='uploadedfile' type='file' /><br />"; print "<input type='submit' name='submit' value='submit' /></form>"; } ?>
php
acctman
source share