37 lines
926 B
PHP
37 lines
926 B
PHP
<?php
|
|
|
|
/* [1] Initialization
|
|
=========================================================*/
|
|
/* (1) Header */
|
|
header('Content-Type: plain/text');
|
|
|
|
/* (2) Checks arguments */
|
|
if( empty($_POST) || !isset($_POST['command']) )
|
|
die('error');
|
|
|
|
|
|
/* [2] Data storage
|
|
=========================================================*/
|
|
/* (1) If have to store data */
|
|
if( $_POST['command'] === 'store' && !empty($_POST['data']) ){
|
|
|
|
/* (2) Stores data */
|
|
file_put_contents( dirname(__FILE__).'/storage.json', $_POST['data']);
|
|
|
|
/* (3) Close connection */
|
|
die('success');
|
|
|
|
/* [3] Data fetch
|
|
=========================================================*/
|
|
/* (1) Checks command */
|
|
}elseif( $_POST['command'] === 'fetch' ){
|
|
|
|
/* (2) Returns data */
|
|
die( file_get_contents( dirname(__FILE__).'/storage.json') );
|
|
}
|
|
|
|
|
|
/* [4] If nothing happened -> error
|
|
=========================================================*/
|
|
die('error');
|