From 9ac85a1afdd69f9abed586204654755987f4e07b Mon Sep 17 00:00:00 2001 From: bruno Date: Fri, 26 Apr 2024 10:47:42 +0200 Subject: [PATCH] Am I dumb? --- lib/upload.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/upload.php b/lib/upload.php index a4aec4b..d632504 100644 --- a/lib/upload.php +++ b/lib/upload.php @@ -183,22 +183,21 @@ function fileExists(int $fileId, bool $onlyMine = true): bool|string if (!$onlyMine && !isModerator()) { $onlyMine = true; } + $query = 'SELECT ID, Path FROM Files WHERE ID = ?' . ($onlyMine ? ' AND UploadedBy = ?' : ''); + $stmtfileexists = $mysqli->prepare($query); if ($onlyMine) { - $stmtfileexists = $mysqli->prepare('SELECT ID, Path FROM Files WHERE ID = ? AND UploadedBy = ?'); - $stmtfileexists->bind_param('ii', $fileId, $_SESSION['id']); + $stmtfileexists->bind_param('ii', $fileId, $_SESSION['ID']); } else { - $stmtfileexists = $mysqli->prepare('SELECT ID, Path FROM Files WHERE ID = ?'); $stmtfileexists->bind_param('i', $fileId); } $filePath = ""; $id = null; - $stmtfileexists->execute(); $stmtfileexists->bind_result($id, $filePath); + $stmtfileexists->execute(); $stmtfileexists->fetch(); - if ($stmtfileexists->num_rows > 0) { + if ($id != null) { return $filePath; } else { - echo "id: $id a path: $filePath"; return false; } }