-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-tExcel.php
64 lines (57 loc) · 1.75 KB
/
admin-tExcel.php
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
error_reporting(0);
session_start();
include('dbconfig.php');
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
if(isset($_POST['save_excel_data']))
{
$fileName = $_FILES['import_file']['name'];
$file_ext = pathinfo($fileName, PATHINFO_EXTENSION);
$allowed_ext = ['xls','csv','xlsx'];
if(in_array($file_ext, $allowed_ext))
{
$inputFileNamePath = $_FILES['import_file']['tmp_name'];
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileNamePath);
$data = $spreadsheet->getActiveSheet()->toArray();
$count = "0";
foreach($data as $row)
{
if($count > 0)
{
$fname = $row['0'];
$phone = $row['1'];
$id = $row['2'];
$password = $row['3'];
$college_id = $row['4'];
$teacherQuery = "INSERT INTO teacher_table (fname, phone, id, password, college_id) VALUES ('$fname', '$phone', '$id', '$password', '$college_id')";
$result = mysqli_query($conn, $teacherQuery);
$msg = true;
}
else
{
$count = "1";
}
}
if(isset($msg))
{
$_SESSION['teacher-excel'] = "Successfully Imported";
header('Location: admin-teacher-excel.php');
exit(0);
}
else
{
$_SESSION['teacher-excel'] = "Not Imported";
header('Location: admin-teacher-excel.php');
exit(0);
}
}
else
{
$_SESSION['teacher-excel'] = "Invalid File";
header('Location: admin-teacher-excel.php');
exit(0);
}
}
?>