This commit is contained in:
2024-04-26 09:46:10 +02:00
parent c261e28427
commit 688a68042c
2 changed files with 16 additions and 15 deletions

View File

@@ -78,8 +78,11 @@ function listFiles($onlyMine = true): array
{
$output = ["Status" => "Fail"];
require_once "lib/account.php";
if (($onlyMine && isLoggedIn()) || (!$onlyMine && isModerator())) {
if (isLoggedIn()) {
global $mysqli;
if (!$onlyMine && !isModerator()) {
$onlyMine = true;
}
$query = "SELECT ID, Path, Type, UploadedAt, UploadedBy FROM Files";
if ($onlyMine) {
@@ -173,7 +176,7 @@ function getUploadPath($type = "unknown", $filename = "hehe"): string
function fileExists(int $fileId, bool $onlyMine = true): bool|string
{
if(!$fileId) {
if (!$fileId) {
return false;
}
global $mysqli;
@@ -192,10 +195,9 @@ function fileExists(int $fileId, bool $onlyMine = true): bool|string
$stmtfileexists->bind_result($id, $filePath);
$stmtfileexists->execute();
$stmtfileexists->fetch();
if ($id != -1){
if ($id != -1) {
return $filePath;
}
else {
} else {
return false;
}
}
@@ -223,7 +225,7 @@ function addToGroup(int $groupId, int $fileId): array
return $output;
}
function getImageURL(int $imageFileID) :string
function getImageURL(int $imageFileID): string
{
global $mysqli;
$path = "";
@@ -236,11 +238,11 @@ function getImageURL(int $imageFileID) :string
}
function deleteFile(int $fileID) :string
function deleteFile(int $fileID): string
{
global $mysqli;
$out = ["Status" => "Fail"];
if(isLoggedIn()) {
if (isLoggedIn()) {
$file_location = fileExists($fileID, !isAdmin());
$query = !isAdmin() ? 'DELETE FROM Files WHERE ID = ? AND UploadedBy = ?' : 'DELETE FROM Files WHERE ID = ?';
$stmtDelete = $mysqli->prepare($query);