5
1
Fork 0
mirror of https://github.com/Anvilcraft/jensmemes synced 2025-03-19 23:20:25 +01:00

Upload ported to API

This commit is contained in:
Timo Ley 2020-08-29 16:46:57 +02:00
parent 6564a5c090
commit 778d229c0f
3 changed files with 3 additions and 80 deletions

View file

@ -1,54 +0,0 @@
<?php
if (isset($_POST['submit'])) {
include('uploadOK.php');
if(empty($tokencookie)) {
$tokencookie = $_POST['token'];
}
$home_dir = "images/" . md5($tokencookie) . "/";
mkdir($home_dir);
$resultToken=mysqli_query($con, "select * from token WHERE token='$tokencookie' OR token='$tokenpost'")or die('ERR_resultToken');
$rowToken=mysqli_fetch_array($resultToken);
if ($uploadOK) {
if ($MaxUpl <= 20) {
$countfiles = count($_FILES['file']['name']);
for ($i = 0; $i < $countfiles; $i++) {
$resultMaxUpl = mysqli_query($con, "select * from token WHERE token='$tokencookie' OR token='$tokenpost'") or die('Error In Session');
$rowMaxUpl = mysqli_fetch_array($resultMaxUpl);
$MaxUpl = $rowMaxUpl['uploadsLast24H'];
$MaxUpl++;
$sqlMaxUpl = "UPDATE token SET uploadsLast24H='$MaxUpl' WHERE token='$tokencookie' OR token='$tokenpost'";
mysqli_query($con, $sqlMaxUpl);
$filename = $_FILES['file']['name'][$i];
move_uploaded_file($_FILES['file']['tmp_name'][$i], $home_dir . $filename);
$memecat = $_POST['type'];
$user = $rowToken['name'];
$path = $home_dir.$filename;
$clientIP =$_SERVER['REMOTE_ADDR'];;
$sqlType = "INSERT INTO images (user, path, cat, ip) VALUES ('$user', '$path', '$memecat', '$clientIP')";
$resultType = mysqli_query($con,$sqlType);
if(!$resultType){
echo 'Error ' .mysqli_error($con);
}
}
if (empty($_COOKIE['token'])) {
$setCookie = $_POST['token'];
setcookie("token", $setCookie, time() + (3600 * 720));
echo "Cookie mit Inhalt gesetzt: " . $setCookie;
} else {
}
} else echo "Heutiges Upload-Limit erreicht!";
} else {
echo "Unautorized!";
}
}
?>

View file

@ -1,22 +0,0 @@
<?php
include('../dbcon.php');
$tokencookie = $_COOKIE['token'];
$resulttoken=mysqli_query($con, "select * from token WHERE token='$tokencookie'")or die('Error In Session');
$rowtoken=mysqli_fetch_array($resulttoken);
$tokenpost = $_POST['token'];
$resultpost=mysqli_query($con, "select * from token WHERE token='$tokenpost'")or die('Error In Session');
$rowpost=mysqli_fetch_array($resultpost);
if(!empty($rowtoken) || !empty($rowpost)){
$uploadOK = true;
//echo "<b>Authenticated.</b>";
}else{
$uploadOK = false;
echo "<b>unauthenticated.</b>";
}
?>

View file

@ -96,7 +96,7 @@
if (!empty($tokencookie)) {
echo '<b style="color:red;">Authentifiziert</b>';
} ?>
<form method='post' action='#' enctype='multipart/form-data'>
<form method='post' action='https://jensmemes.tilera.xyz/api/upload' enctype='multipart/form-data'>
<input type="file" id="real-file" hidden="hidden" name="file[]" multiple="" />
<button type="button" id="custom-button">Browse...</button>
<span id="custom-text"></span>
@ -105,10 +105,11 @@
echo '
<input type="text" name="token" id="token" placeholder="Token">';
} else {
echo '<input type="hidden" name="token" value="' . $tokencookie . '">';
}
?>
<label for="type">Memetype</label>
<select id="type" name="type">
<select id="type" name="category">
<?php
foreach ($cats as $cat) {
echo '<option value="' . $cat->id . '">' . $cat->name . '</option>';
@ -126,8 +127,6 @@
<?php
include "dbcon.php";
include "incl/uploadOK.php";
include "incl/upload.php";
include 'incl/img.php';
include 'incl/clientIP.php';
?>