Test file list
This commit is contained in:
parent
c73d471fab
commit
b764dfad8b
@ -271,6 +271,9 @@ async function onPageLoad() {
|
||||
if ("news" === currentSite && "index" === currentPage) {
|
||||
await articleInit();
|
||||
}
|
||||
if ("files" === currentSite && "list" === currentPage) {
|
||||
await listFiles();
|
||||
}
|
||||
}
|
||||
|
||||
async function navigateTo(site, page) {
|
||||
@ -557,5 +560,32 @@ function uploadFile() {
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
function deleteFile(fileID){
|
||||
let formData = new FormData();
|
||||
formData.append('action', 'deleteFile');
|
||||
formData.append('file_id', fileID);
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/upload', true);
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
async function listFiles() {
|
||||
let fileListContainer = document.getElementById("filelist");
|
||||
let formData = new FormData();
|
||||
formData.append('action', 'getAllFiles');
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/upload', true);
|
||||
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
displayList(xhr.responseText, fileListContainer, deleteFile);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(formData);
|
||||
}
|
@ -9,6 +9,7 @@ function endpoint($endpoint_data): array
|
||||
"getMyFiles" => listFiles(),
|
||||
"getAllFiles" => listFiles(false),
|
||||
"uploadFiles" => parseIncomingFiles(),
|
||||
"deleteFile" => deleteFile($endpoint_data['file_id']),
|
||||
"addToGroup" => addToGroup($endpoint_data['group_id'], $endpoint_data['file_id']),
|
||||
"myFileExists" => fileExists($endpoint_data['file_id'], ),
|
||||
"FileExists" => fileExists($endpoint_data['file_id'], false),
|
||||
|
@ -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;
|
||||
}
|
3
pages/files/list.html
Normal file
3
pages/files/list.html
Normal file
@ -0,0 +1,3 @@
|
||||
<!--suppress HtmlUnknownTag, HtmlUnknownTag -->
|
||||
<page minimal_permission_level="2" secret="yes" page_title="Zoznam"></page>
|
||||
<div id="filelist"></div>
|
Loading…
Reference in New Issue
Block a user