This repository has been archived on 2026-03-14. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
kekec_bbs/backup.php
T
2023-05-21 22:51:32 +09:00

49 lines
984 B
PHP

<?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]);
}
?>