Excel File Upload to Database Format (csv) PHP
index.php (frontend-file)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form method="POST" action="process.php" enctype="multipart/form-data">
Choose File :<input type="file" name="userfile" required><br><br>
<input type="submit" name="usersave" value="submit">
</form>
</body>
</html>
backend file
<?php
include "conn.php";
//testing sucessfully done
//echo "<pre>";
//print_r($_FILES);
//echo "</pre>";
if (isset($_POST['usersave']))
{
$upload_file = $_FILES['userfile']['tmp_name'];
$handle = fopen($upload_file,"r");
$i = 0;
while (($myfile = fgetcsv($handle,1000,","))!==false)
{
$name = $myfile[0];
$age = $myfile[1];
$phone = $myfile[2];
$query = "INSERT INTO exceltable(dbname,dbage,dbphone) VALUES ('$name','$age','$phone')";
$query_1 = mysqli_query($conn,$query);
$i++;
}
}
?>
(Excel File)
Comments
Post a Comment