|
| | |
| Main » 2012 » November » 6 » Read Csv Files without using any external class
10:21 PM Read Csv Files without using any external class |
how to read Csv Files in php without using any external class
<?php
if($_REQUEST)
{
$filePath="./uploads/". $_FILES["userfile"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"] ,$filePath);
$sql = array(); if (($handle = fopen($filePath, "r")) !== FALSE) { $i=1; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
//all the column data will come of a subsequent row will cone in data array if($i==1) { $i++; continue; } else { $sql[] = '("'.$data[1].'","'.$data[2].'","'.$data[3].'","'.$data[4].'")'; } }
fclose($handle); } // make a sql query to execute.. $data_query='INSERT INTO health_care_standard_uploads(name,age,address,sex) VALUES '.implode(',', $sql); $res=mysql_query($data_query); if($res)
{ echo '<script>alert("succesfully imported !");</script>';
} }
?>
|
Category: Web Development |
Views: 526 |
Added by: admin-priyank
| Rating: 5.0/1 |
| |
| | |
|
Calendar |
| « November 2012 » | Su | Mo | Tu | We | Th | Fr | Sa | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| |
|
Our poll |
| | |
|
Statistics |
|
Total online: 9 Guests: 9 Users: 0 | |
|
|