This commit is contained in:
2024-04-26 01:17:49 +02:00
parent 0fca1b000b
commit 20ca96ba05
5 changed files with 61 additions and 9 deletions

View File

@@ -241,11 +241,23 @@ function getImageURL(int $imageFileID) :string
function deleteFile(int $fileID) :string
{
global $mysqli;
$out = ["Status" => "Fail"];
$file_location = fileExists($fileID, false);
if ($file_location){
if(unlink($file_location)) {
$out['Status'] = 'Success';
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);
if (!isAdmin()) {
$stmtDelete->bind_param('ii', $fileID, $_SESSION['id']);
} else {
$stmtDelete->bind_param('i', $fileID);
}
$stmtDelete->execute();
$stmtDelete->fetch();
if ($file_location) {
if (unlink($file_location) && $stmtDelete->affected_rows > 0) {
$out['Status'] = 'Success';
}
}
}
return $out;