-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_handler.php
43 lines (32 loc) · 1.18 KB
/
file_handler.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
<?php
require_once("inc/db.php");
require_once("inc/functions.php");
header('Content-Type: text/plain; charset=utf-8');
try {
if ((($_FILES["file"]["type"] == "application/xml") || ($_FILES["file"]["type"] == "text/xml"))
&& ($_FILES["file"]["size"] < 100000)) {
$file = simplexml_load_file($_FILES["file"]["tmp_name"]);
foreach ($file->item as $item) {
$title = clear($item->title);
$year = clear($item->year);
if (!preg_match('/(1|2)[0-9]{3}/', $year)) {
$year = date("Y");
}
$format = clear($item->format);
$castObj = $item->cast;
$cast = array();
foreach ($castObj->actor as $key => $value) {
array_push($cast, [
clear($value->name->__toString()),
clear($value->surname->__toString())
]);
}
addItem($db, $title, $year, $format, $cast);
}
header("Location: index.php");
} else {
echo "Sorry, there was an error uploading your file. Only XML files are allowed.";
}
} catch (RuntimeException $e) {
echo $e->getMessage();
}