Test file list

This commit is contained in:
2024-04-25 15:01:17 +02:00
parent c73d471fab
commit b764dfad8b
5 changed files with 56 additions and 3 deletions

View File

@@ -174,7 +174,7 @@ function getUploadPath($type = "unknown", $filename = "hehe"): string
}
}
function fileExists(int $fileId, bool $onlyMine = true): bool
function fileExists(int $fileId, bool $onlyMine = true): bool|string
{
if(!$fileId) {
return false;
@@ -183,15 +183,22 @@ function fileExists(int $fileId, bool $onlyMine = true): bool
if (!$onlyMine && !isAdmin()) {
$onlyMine = true;
}
$query = 'SELECT ID FROM Files WHERE ID = ?' . $onlyMine ? ' AND UploadedBy = ?' : '';
$query = 'SELECT Path FROM Files WHERE ID = ?' . $onlyMine ? ' AND UploadedBy = ?' : '';
$stmtfileexists = $mysqli->prepare($query);
if ($onlyMine) {
$stmtfileexists->bind_param('ii', $fileId, $_SESSION['id']);
} else {
$stmtfileexists->bind_param('i', $fileId);
}
$filePath = "";
$stmtfileexists->bind_result($filePath);
$stmtfileexists->execute();
return $stmtfileexists->affected_rows > 0;
if (!empty($filePath)){
return $filePath;
}
else {
return false;
}
}
function addToGroup(int $groupId, int $fileId): array
@@ -228,4 +235,16 @@ function getImageURL(int $imageFileID) :string
$stmtget->fetch();
return $path;
}
function deleteFile(int $fileID) :string
{
$out = ["Status" => "Fail"];
$file_location = fileExists($fileID, false);
if ($file_location){
if(unlink($file_location)) {
$out['Status'] = 'Success';
}
}
return $out;
}