Git リポジトリ化
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
define ('SAVE_DIR', 'draft/');
|
||||
|
||||
$json = getParamJSON ();
|
||||
|
||||
if (!(isset ($json['data'])))
|
||||
{
|
||||
sendResult (false, 'Empty query Parameter: data');
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!(preg_match ('/^data:image\/png;base64,/', $json['data'])))
|
||||
{
|
||||
sendResult (false, 'Not Allow data type: data');
|
||||
exit (1);
|
||||
}
|
||||
|
||||
$data = $json['data'];
|
||||
$data = str_replace ('data:image/png;base64,', '', $data);
|
||||
$data = str_replace (' ', '+', $data);
|
||||
$image = base64_decode ($data);
|
||||
|
||||
$file = sprintf ('%s.png', $_GET['id']);
|
||||
$result = file_put_contents (SAVE_DIR . $file, $image, LOCK_EX);
|
||||
|
||||
setcookie ('backup', $file, time () + 60 * 60 * 24 * 30);
|
||||
|
||||
|
||||
function
|
||||
getParamJSON ()
|
||||
{
|
||||
$buff = file_get_contents ('php://input');
|
||||
$json = json_decode ($buff, true);
|
||||
|
||||
return ($json);
|
||||
}
|
||||
|
||||
function
|
||||
sendResult ($status, $data)
|
||||
{
|
||||
header ('Access-Control-Allow-Origin: *');
|
||||
header ('Access-Control-Allow-Headers: *');
|
||||
|
||||
echo json_encode(["status" => $status,
|
||||
"result" => $data]);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user