Monday 5 December 2011

How To Upload .csv file (php)



<?php
$counter = 1;
$row = 1;
if(isset($_FILES['up_info_file']) && $_FILES['up_info_file']!='' ){

// $ext = getFileExtension($_FILES['up_info_file']['name']);
$ext = substr($_FILES['up_info_file']['name'], strrpos($_FILES['up_info_file']['name'], '.'));
if($ext == '.csv'){
$handle = fopen($_FILES['up_info_file']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
//echo '<pre>'; print_r($data[1]); exit;
$num = count($data);
$row++;
$counter;
if($data[0] != '' && $counter != 0){
echo '<pre>'; print_r($data[1]);
echo '<pre>'; print_r($data[0]);
}
}
$counter++;
}
}// end if file not empty
else{ echo "File is Empty";}
//while endss
fclose($handle);
?>

No comments:

Post a Comment