-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
32 lines (28 loc) · 1012 Bytes
/
Copy pathupload.php
File metadata and controls
32 lines (28 loc) · 1012 Bytes
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
<?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);
header('Content-Type: application/json');
echo json_encode($xml);
} else {
header('Content-Type: application/json');
echo json_encode($errors);
}
}
?>