forked from naali/damones
-
Notifications
You must be signed in to change notification settings - Fork 0
/
framesaver.php
38 lines (30 loc) · 1.1 KB
/
framesaver.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
<?php
header('Content-Type: application/json');
$result = array();
$path = 'frames/';
$filename = 'frame_';
if (isset($_POST)) {
if (isset($_POST['action'])) {
if ($_POST['action']==='saveframe') {
if (isset($_POST['framenumber']) && isset($_POST['framedata'])) {
$framenumber = (int)$_POST['framenumber'];
$framenumber = str_pad("".$framenumber, 6, '0', STR_PAD_LEFT);
$framedata = $_POST['framedata'];
$framedata = explode(',', $framedata, 2);
$framedata = base64_decode($framedata[1]);
$res = file_put_contents($path.$filename.$framenumber.'.png', $framedata);
$result = array( 'status' => 'ok', 'framestatus' => $res, 'framenumber' => $framenumber );
} else {
$result = array( 'status' => 'fail', 'error' => 'MISSING_SAVEFRAME_PARAMETERS');
}
} else {
$result = array( 'status' => 'fail', 'error' => 'INVALID_ACTION');
}
} else {
$result = array( 'status' => 'fail', 'error' => 'MISSING_ACTION');
}
} else {
$result = array( 'status' => 'fail', 'error' => 'MISSING_PARAMETERS');
}
echo json_encode($result);
?>