-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-cExcel.php
68 lines (61 loc) · 1.96 KB
/
admin-cExcel.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
65
66
67
68
<?php
#error_reporting(0);
session_start();
include('database.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'];
$class_name = $row['4'];
$class_id = $row['5'];
$college_id = $row['6'];
$classQuery = "INSERT INTO class_admin (fname, phone, id, password, class_name, class_id, college_id) VALUES ('$fname', '$phone', '$id', '$password', '$class_name', '$class_id', '$college_id')";
$result = mysqli_query($data, $classQuery);
$msg = true;
}
else
{
$count = "1";
$_SESSION['class-excel-err'] = "Error!";
header('Location: admin-ca-excel.php');
}
}
if(isset($msg))
{
$_SESSION['class-excel'] = "Successfully Imported";
header('Location: admin-ca-excel.php');
exit(0);
}
else
{
$_SESSION['class-excel'] = "Not Imported";
header('Location: admin-ca-excel.php');
exit(0);
}
}
else
{
$_SESSION['class-excel'] = "Invalid File";
header('Location: admin-ca-excel.php');
exit(0);
}
}
?>