Do something
This commit is contained in:
@@ -43,7 +43,7 @@ function getIncomingFiles(): array
|
||||
return $files3;
|
||||
}
|
||||
|
||||
function saveUploadedFileInDatabase($filePath, $fileType):bool
|
||||
function saveUploadedFileInDatabase($filePath, $fileType): bool
|
||||
{
|
||||
global $mysqli;
|
||||
$stmt = $mysqli->prepare("INSERT INTO Files (Path, Type, UploadedBy, UploadedAt) VALUES (?, ?, ?, NOW())");
|
||||
@@ -91,20 +91,20 @@ function doImageUpload($inFile, $outFile): bool
|
||||
}
|
||||
}
|
||||
|
||||
function listFiles($onlyMine = true):array
|
||||
function listFiles($onlyMine = true): array
|
||||
{
|
||||
$output = ["Status" => "Fail"];
|
||||
require_once "lib/account.php";
|
||||
if(($onlyMine && isLoggedIn()) || (!$onlyMine && isModerator())) {
|
||||
if (($onlyMine && isLoggedIn()) || (!$onlyMine && isModerator())) {
|
||||
global $mysqli;
|
||||
$query = "SELECT ID, Path, Type, UploadedAt, UploadedBy FROM Files";
|
||||
|
||||
if($onlyMine){
|
||||
if ($onlyMine) {
|
||||
$query .= " WHERE UploadedBy = ?";
|
||||
}
|
||||
|
||||
$stmt = $mysqli->prepare($query);
|
||||
if($onlyMine) {
|
||||
if ($onlyMine) {
|
||||
$stmt->bind_param("i", $_SESSION["ID"]);
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ function parseIncomingFiles(): array
|
||||
}
|
||||
}
|
||||
$output = ["Status" => "Fail"];
|
||||
if($success){
|
||||
if ($success) {
|
||||
$output["Status"] = "Success";
|
||||
}
|
||||
return $output;
|
||||
@@ -180,10 +180,52 @@ function getUploadPath($type = "unknown", $filename = "hehe"): string
|
||||
'image' => 'webp',
|
||||
default => 'dummy',
|
||||
};
|
||||
if($extension != "dummy") {
|
||||
if ($extension != "dummy") {
|
||||
return "uploads/$type/$id/$date/$filename.$extension";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function fileExists(int $fileId, bool $onlyMine = true): bool
|
||||
{
|
||||
if(!$fileId) {
|
||||
return false;
|
||||
}
|
||||
global $mysqli;
|
||||
if (!$onlyMine && !isAdmin()) {
|
||||
$onlyMine = true;
|
||||
}
|
||||
$query = 'SELECT ID 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);
|
||||
}
|
||||
$stmtfileexists->execute();
|
||||
return $stmtfileexists->affected_rows > 0;
|
||||
}
|
||||
|
||||
function addToGroup(int $groupId, int $fileId): bool
|
||||
{
|
||||
$output = ["Status" => "Fail"];
|
||||
if (!$groupId || !$fileId) {
|
||||
return $output;
|
||||
}
|
||||
global $mysqli;
|
||||
$stmtcheck = $mysqli->prepare('SELECT ID FROM FileGroups WHERE CreatorID != ? AND ID = ?');
|
||||
$stmtcheck->bind_param('ii', $_SESSION['id'], $groupId);
|
||||
$stmtcheck->execute();
|
||||
if ($stmtcheck->affected_rows == 0) {
|
||||
if (fileExists($fileId, false)) {
|
||||
$stmtadd = $mysqli->prepare('INSERT INTO FileGroups (FileID, CreatorID, ID) VALUES (?, ?, ?)');
|
||||
$stmtadd->bind_param('iii', $fileId, $_SESSION['id'], $groupId);
|
||||
$stmtadd->execute();
|
||||
if ($stmtadd->affected_rows > 0) {
|
||||
$output["Status"] = "Success";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
Reference in New Issue
Block a user