キケッツ掲示板のリポジトリです. https://bbs.kekec.wiki
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

55 lines
1.0 KiB

  1. <?php
  2. define ('SAVE_DIR', "${_SERVER['DOCUMENT_ROOT']}/drafts/");
  3. $json = getParamJSON ();
  4. if (!(isset ($json['data'])))
  5. {
  6. sendResult (false, 'Empty query Parameter: data');
  7. exit (1);
  8. }
  9. if (!(preg_match ('/^data:image\/png;base64,/', $json['data'])))
  10. {
  11. sendResult (false, 'Not Allow data type: data');
  12. exit (1);
  13. }
  14. $data = $json['data'];
  15. $data = str_replace ('data:image/png;base64,', '', $data);
  16. $data = str_replace (' ', '+', $data);
  17. $image = base64_decode ($data);
  18. $file = sprintf ('%s.png', $_GET['id']);
  19. $result = file_put_contents (SAVE_DIR . $file, $image, LOCK_EX);
  20. setcookie ('backup', $file, time () + 60 * 60 * 24 * 30);
  21. function
  22. getParamJSON ():
  23. array
  24. {
  25. $buff = file_get_contents ('php://input');
  26. $json = json_decode ($buff, true);
  27. return ($json);
  28. }
  29. function
  30. sendResult (
  31. $status,
  32. $data):
  33. string
  34. {
  35. header ('Access-Control-Allow-Origin: *');
  36. header ('Access-Control-Allow-Headers: *');
  37. echo json_encode(["status" => $status,
  38. "result" => $data]);
  39. }
  40. ?>