-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.php
47 lines (40 loc) · 1.49 KB
/
import.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
<?php
session_start();
// Check if the user is logged in and has admin role
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: login.php");
exit();
}
// This PHP script handles the uploading of a SQLite database file.
// The target database path is defined.
$databasePath = __DIR__ . '/assets/db/timetracking.sqlite';
// Check if a file has been submitted via the upload form.
if (!empty($_FILES['dbFile']['name'])) {
// Save temporary file information.
$tempFile = $_FILES['dbFile']['tmp_name'];
$uploadFileName = $_FILES['dbFile']['name'];
// Retrieve the file extension of the uploaded file.
$fileExtension = pathinfo($uploadFileName, PATHINFO_EXTENSION);
// Verify that the file extension is sqlite.
if ($fileExtension !== 'sqlite') {
// Set error message and redirect
$_SESSION['import_error'] = "No valid SQLite database provided.";
header("Location: settings.php");
exit;
}
// Move the temporary file to its final destination.
if (move_uploaded_file($tempFile, $databasePath)) {
// Set success message and redirect
$_SESSION['import_success'] = "Database successfully imported.";
} else {
// Set error message and redirect
$_SESSION['import_error'] = "Error in import.";
}
} else {
// Set error message and redirect
$_SESSION['import_error'] = "No file in upload.";
}
// Redirect back to settings.php
header("Location: settings.php");
exit;
?>