1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-11 12:29:29 +00:00
8bitworkshop/share.php
2016-12-15 20:21:51 -05:00

31 lines
495 B
PHP

<?php
$OUTDIR = $_SERVER['DOCUMENT_ROOT'] . '/.storage';
$filename = $_POST['filename'];
$text = $_POST['text'];
if (!$filename || !$text) {
http_response_code(400);
die;
}
$rec = array(
'filename' => $filename,
'text' => $text,
);
$json = json_encode($rec);
$hash = md5($json);
$outfn = "$OUTDIR/$hash";
$result = file_put_contents($outfn, $json);
if (!$result) {
http_response_code(500);
die;
}
header('Content-Type: text/json');
echo json_encode(array('key' => $hash));
?>