forked from mathsnz/ADSync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.php
More file actions
56 lines (49 loc) · 1.15 KB
/
json.php
File metadata and controls
56 lines (49 loc) · 1.15 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
50
51
52
53
54
55
56
<?php
include 'config.php';
header("Content-type: application/json");
//Get Data
$data = file_get_contents('php://input');
if (!file_exists($storage)) {
mkdir($storage, 0777, true);
}
if (!file_exists($storage.'dsdata/')) {
mkdir($storage.'dsdata/', 0777, true);
}
//Check for data
if(isset($data)) {
//create a random string to avoid duplicate files being created.
$randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
//Write xml file
$file = fopen($storage.time().$randomString.".json", "w") or die("Unable to open file!");
fwrite($file, $data);
fclose($file);
//Generate Response
$string = <<<JSON
{"SMSDirectoryData": {
"error": 0,
"result": "OK",
"service": "ADSync",
"version": 1.0,
"status": "Ready"
}}
JSON;
//Display Response
echo $string;
}
else {
//Generate Response
$string = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<SMSDirectoryData>
<error>401</error>
<result>No Data</result>
<service>ADSync</service>
<version>1.0</version>
<status>Ready</status>
</SMSDirectoryData>
XML;
//Display Response
$xml = new SimpleXMLElement($string);
echo $xml->asXML();
}
?>