upload csv file in php
if (isset($_POST['import'])) {
if ($_FILES['file']['name']) {
$filename = explode(".", $_FILES['file']['name']);
if ($filename[1] == 'csv') {
$handle = fopen($_FILES['file']['tmp_name'], "r");
$i = 0;
while ($getData = fgetcsv($handle)) {
if($i > 0){
$productName = $getData[0];
$productDesc = $getData[1];
$productQty = $getData[2];
$productPrice = $getData[3];
$productTotal = $getData[4];
$sql = "INSERT INTO import (productName,productDesc,productQty,productPrice,productTotal) VALUES('" . $getData[0] . "','" . $getData[1] . "','" . $getData[2] . "','" . $getData[3] . "','" . $getData[4] . "')";
$result = mysqli_query($conn, $sql);
header("Location:import.php");
}
$i++;
}
fclose($handle);
}
}
}
Check your table name,column name & where you want to redirect using header function.