キケッツ掲示板のリポジトリです. 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.

backup.php 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. define ('SAVE_DIR', 'draft/');
  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. {
  24. $buff = file_get_contents ('php://input');
  25. $json = json_decode ($buff, true);
  26. return ($json);
  27. }
  28. function
  29. sendResult ($status, $data)
  30. {
  31. header ('Access-Control-Allow-Origin: *');
  32. header ('Access-Control-Allow-Headers: *');
  33. echo json_encode(["status" => $status,
  34. "result" => $data]);
  35. }
  36. ?>