-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
74 lines (62 loc) · 2.62 KB
/
index.php
File metadata and controls
74 lines (62 loc) · 2.62 KB
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
69
70
71
72
73
74
<?php
require __DIR__.'/vendor/autoload.php';
include 'excel_reader2.php';
use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Excel</title>
</head>
<body>
<h1>Import Excel to Firebase</h1><br>
<form method="post" enctype="multipart/form-data">
<p>Pilih file excel yang akan di import</p>
<input type="file" name="fileimport">
<br><br>
<input type="submit" name="btnimport" value="Import Excel">
</form>
<?php
if (isset($_POST['btnimport'])) {
if (isset($_FILES['fileimport'])) {
//Tentukan alamat firebase realtime database
$factory = (new Factory())
//Isi dengan alamat Firebase realtime database anda
->withDatabaseUri('https://alamat/firebase/anda');
//Initialisasi variable database
$database = $factory->createDatabase();
// upload file xls
$target = basename($_FILES['fileimport']['name']) ;
move_uploaded_file($_FILES['fileimport']['tmp_name'], $target);
// beri permisi agar file xls dapat di baca
chmod($_FILES['fileimport']['name'],0777);
// mengambil isi file xls
$data = new Spreadsheet_Excel_Reader($_FILES['fileimport']['name'],false);
// menghitung jumlah baris data sheet1
$jumlah_baris_sheet1 = $data->rowcount(0);
//Import sheet mahasiswa
for ($i=2; $i<=$jumlah_baris_sheet1; $i++) {
// menangkap data dan memasukkan ke variabel sesuai dengan kolumnya masing-masing
$nimMahasiswa = $data->val($i, 1, 0);
$namaMahasiswa = $data->val($i, 2, 0);
$kelasMahasiswa = $data->val($i, 3, 0);
$prodiMahasiswa = $data->val($i, 4, 0);
//Masukkan data hasil import ke firebase
$database->getReference('mahasiswa')->push([
'nim' => $nimMahasiswa,
'nama' => $namaMahasiswa,
'kelas' => $kelasMahasiswa,
'prodi' => $prodiMahasiswa,
]
);
}
unlink($_FILES['fileimport']['name']);
}
}
?>
</body>
</html>