diff --git a/lib/upload.php b/lib/upload.php index 40afcb1..9a20ee8 100644 --- a/lib/upload.php +++ b/lib/upload.php @@ -183,7 +183,7 @@ function fileExists(int $fileId, bool $onlyMine = true): bool|string if (!$onlyMine && !isModerator()) { $onlyMine = true; } - $query = $onlyMine ? 'SELECT ID, Path FROM Files WHERE ID = ? AND UploadedBy = ?' : 'SELECT ID, Path FROM Files WHERE ID = ?'; + $query = 'SELECT ID, Path FROM Files WHERE ID = ?' . ($onlyMine ? ' AND UploadedBy = ?' : ''); $stmtfileexists = $mysqli->prepare($query); if ($onlyMine) { $stmtfileexists->bind_param('ii', $fileId, $_SESSION['id']); @@ -191,11 +191,11 @@ function fileExists(int $fileId, bool $onlyMine = true): bool|string $stmtfileexists->bind_param('i', $fileId); } $filePath = ""; - $id = -1; + $id = null; $stmtfileexists->bind_result($id, $filePath); $stmtfileexists->execute(); $stmtfileexists->fetch(); - if ($id != -1) { + if ($stmtfileexists->num_rows > 0) { return $filePath; } else { return false;