Hello guys
this forum helped me alone for completing my projects that is y i am going to post one article hope you like it.........
1->create an excel sheet and enter data in that then at the time of saving saving it as a csv format and below is the code that will going to work perfectly without any problem.
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
if ($_FILES["file"]["size"] < 200000)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
$path = "upload/" . $_FILES["file"]["name"];
}
if(findexts($path) == csv){
$file=file_get_contents($path);
$rows=explode("\n", $file);
$data = array();
print_r($rows);
$count =count($rows)-1;
for($i=1;$i<$count;$i++){
$sql = "insert into tblbooks(field1,field2,field3)values('".str_replace(",","','",$rows[$i])."')";
$DB_site->query($sql);
}
unlink($path);
unset($rows);
}
else{
echo "invalid file";
error_reporting(0);
unlink($path);
}
}
}
else{
echo "Invalid file";
}
i hope you like it