forked from asxzy/Program-O
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validateAIML.php
88 lines (81 loc) · 2.19 KB
/
validateAIML.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
if (!file_exists('config/global_config.php'))
{
header('location: install/install_programo.php');
}
else
{
$thisFile = __FILE__;
require_once ('config/global_config.php');
if (!defined('SCRIPT_INSTALLED'))
header('location: ' . _INSTALL_PATH_ . 'install_programo.php');
}
$status = 'No file to validate. Please select a file to test.';
if (!empty ($_FILES))
{
$target = _UPLOAD_PATH_ . basename($_FILES['uploaded']['name']);
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
$fileName = str_replace($uploadDir, '' . $target);
libxml_use_internal_errors(true);
$xml = new DOMDocument();
$xml->load($target);
if (!$xml->validate())
{
$status = "File $fileName is invalid!<br />\n";
libxml_display_errors();
}
else
{
$status = "File $fileName is valid.<br />\n";
}
}
}
function libxml_display_error($error)
{
$return = "<br/>\n";
switch ($error->level)
{
case LIBXML_ERR_WARNING :
$return .= "<b>Warning $error->code</b>: ";
break;
case LIBXML_ERR_ERROR :
$return .= "<b>Error $error->code</b>: ";
break;
case LIBXML_ERR_FATAL :
$return .= "<b>Fatal Error $error->code</b>: ";
break;
}
$return .= trim($error->message);
if ($error->file)
{
$return .= " in <b>$error->file</b>";
}
$return .= " on line <b>$error->line</b>\n";
return $return;
}
function libxml_display_errors()
{
global $status;
$errors = libxml_get_errors();
foreach ($errors as $error)
{
$status .= libxml_display_error($error) . "<br />\n";
}
libxml_clear_errors();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Program O AIML File Validation Utility</title>
</head>
<body>
<form enctype="multipart/form-data" action="validateAIML.php" method="post">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Validate" />
</form>
<br /><p><?php echo $status ?></p>
</body>
</html>