-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.php
More file actions
49 lines (41 loc) · 1.37 KB
/
Copy pathsave.php
File metadata and controls
49 lines (41 loc) · 1.37 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
<?php
include 'db_connect.php';
if(isset($_FILES['fileToUpload'])){
$errors= array();
$file_name = $_FILES['fileToUpload']['name'];
$file_size = $_FILES['fileToUpload']['size'];
$file_tmp = $_FILES['fileToUpload']['tmp_name'];
$file_type = $_FILES['fileToUpload']['type'];
$file_parts = explode('.', $_FILES['fileToUpload']['name']);
$file_ext = strtolower(end($file_parts));
$extensions= array("xml");
if(in_array($file_ext,$extensions) === false){
$errors[]="extension not allowed, please choose a XML file.";
}
if(empty($errors) == true){
if (!is_dir('uploads')) {
mkdir('uploads', 0777, true);
}
move_uploaded_file($file_tmp,"uploads/".$file_name);
// Load and return the XML content
$xml = simplexml_load_file("uploads/".$file_name);
// Database operations
$title = $_POST["title"];
$description = $_POST["description"];
$sql = "INSERT INTO MyTable (title, description, file) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
$xmlContent = $xml->asXML();
$stmt->bind_param("sss", $title, $description, $xmlContent);
$stmt->execute();
if ($stmt->affected_rows > 0) {
echo "Data saved successfully";
} else {
echo "Failed to save";
}
$stmt->close();
$conn->close();
} else {
echo implode(", ", $errors);
}
}
?>