forked from Adleraci/adlerka.top
Test file list
This commit is contained in:
@@ -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;
|
||||
}
|
Reference in New Issue
Block a user