add mime type

This commit is contained in:
Bruno Rybársky 2023-06-10 11:04:08 +02:00
parent 5834a92a3f
commit 08098b5417
No known key found for this signature in database
GPG Key ID: DFE2C061EF985CD4
3 changed files with 26 additions and 8 deletions

@ -47,17 +47,22 @@ if (!empty($action) && $_SESSION["password"] == $config["admin_pwd"]){
}
if ($action == "getcontent"){
$stmt4 = $mysqli->prepare("SELECT `ContentID`, `Content` FROM Content");
$stmt4->bind_result ($contentid, $content);
$stmt4 = $mysqli->prepare("SELECT `ContentID`, `Type`, `Content` FROM Content");
$stmt4->bind_result ($contentid, $type, $content);
$stmt4->execute();
$stmt4->store_result();
$out = "<table><tbody><tr><th>Content ID</th><th>Content</th><th>Button</th></tr>";
while ($stmt4->fetch()) {
$id = htmlspecialchars($contentid);
$content = htmlspecialchars($content);
if(empty($type)){
$content = htmlspecialchars($content);
}
else{
$content = "Binary data";
}
$out = $out . "<tr><td>$id</td><td>$content</td><td><button onclick=\"delcthis('$id')\">Delete</button></td></tr>";
}
$out = $out . "<tr><td><input id=\"addidc\" placeholder=\"Content ID\"></td><td><textarea id=\"addcontentc\" placeholder=\"Content\"></textarea></td><td><button id=\"contentadder\" onclick=\"justaddc()\">Add</button></td></tr>";
$out = $out . "<tr><td><input id=\"addidc\" placeholder=\"Content ID\"></td><td><textarea id=\"addcontentc\" placeholder=\"Content\"></textarea></td><td><input id=\"addtypec\" placeholder=\"MIME Type(when set the data must be Base64)\"></td></td><td><button id=\"contentadder\" onclick=\"justaddc()\">Add</button></td></tr>";
$out = $out . "</tbody></table>";
echo $out;
}
@ -70,8 +75,14 @@ if (!empty($action) && $_SESSION["password"] == $config["admin_pwd"]){
}
if ($action == "setcontent" && !empty($_POST["id"]) && !empty($_POST["content"])){
$stmt6 = $mysqli->prepare("INSERT INTO Content (`ContentID`, `Content`) VALUES (?, ?);");
$stmt6->bind_param('ss', $_POST["id"], $_POST["content"]);
$stmt6 = $mysqli->prepare("INSERT INTO Content (`ContentID`, `Type`, `Content`) VALUES (?, ?, ?);");
if (!empty($_POST["type"])){
$decoded = base64_decode($_POST["content"]);
$stmt6->bind_param('sss', $_POST["id"], $_POST["type"], $decoded);
}
else{
$stmt6->bind_param('sss', $_POST["id"], "", $_POST["content"]);
}
$stmt6->execute();
$stmt6->store_result();
}

@ -33,12 +33,15 @@
function justaddc(){
let id = $("#addidc").val();
let content = $("#addcontentc").val();
let type = "normal";
type = $("#addtypec").val();
$.post("api.php",
{
action: "setcontent",
password: password,
id: id,
content: content,
type: type,
}, function( data ) {
getcontents();
});

@ -19,9 +19,9 @@ if (!empty($idcko)){
die("Nonexistent link");
}
while ($stmt1->fetch()) {
$stmt2 = $mysqli->prepare("SELECT `Content` FROM Content WHERE `ContentID` = ?");
$stmt2 = $mysqli->prepare("SELECT `Type`, `Content` FROM Content WHERE `ContentID` = ?");
$stmt2->bind_param("s", $contentid);
$stmt2->bind_result ($content);
$stmt2->bind_result ($type, $content);
$stmt2->execute();
$stmt2->store_result();
if ($stmt2->num_rows() < 1) {
@ -33,6 +33,10 @@ if (!empty($idcko)){
$stmt3->bind_param('ssssss', $action, $idcko, $contentid, $curdate, $nickname, $ipcka);
$stmt3->execute();
$stmt3->store_result();
if ($type == 1){
}
header("Content-Type: $type");
echo $content;
}