Added photo voting
This commit is contained in:
30
vote.php
Normal file
30
vote.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
$votes_file = 'votes.json';
|
||||
|
||||
if (isset($_GET['name'])) {
|
||||
$name = $_GET['name'];
|
||||
$contents = file_get_contents($votes_file);
|
||||
if ($contents === false) {
|
||||
$contents = '{}';
|
||||
}
|
||||
$contents = json_decode($contents, true);
|
||||
$data = $contents[$name] ?? [];
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
die(json_encode($data));
|
||||
} elseif (isset($_POST['name']) && isset($_POST['uid']) && isset($_POST['vote'])) {
|
||||
$name = $_POST['name'];
|
||||
$contents = file_get_contents($votes_file);
|
||||
if ($contents === false) {
|
||||
$contents = '{}';
|
||||
}
|
||||
$contents = json_decode($contents, true);
|
||||
$data = $contents[$name] ?? [];
|
||||
$data[$_POST['uid']] = $_POST['vote'];
|
||||
$contents[$name] = $data;
|
||||
file_put_contents($votes_file, json_encode($contents));
|
||||
header('HTTP/1.1 204 No Content');
|
||||
die();
|
||||
} else {
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
die();
|
||||
}
|
Reference in New Issue
Block a user