Compare commits

..

4 Commits

Author SHA1 Message Date
Felix Ivo
5ef5de9b98 fixed document upload location 2025-07-08 10:51:57 +02:00
Felix Ivo
92e162283e fixed directory location 2025-07-07 15:08:56 +02:00
Felix Ivo
26fb9b54b6 fixed upoad folder missing 2025-07-07 14:52:46 +02:00
Felix Ivo
b4fcc4892c fixed sorting 2025-07-07 14:50:48 +02:00
6 changed files with 12 additions and 8 deletions

View File

@@ -122,7 +122,7 @@ class NotesController
$isAdmin = $_SESSION['role'] === 'admin'; $isAdmin = $_SESSION['role'] === 'admin';
$userid = $_SESSION['user_id']; $userid = $_SESSION['user_id'];
$files = $this->notesModel->selectFiles($userid, true); $files = $this->notesModel->selectFiles($userid, true, $sortBy, $sortOrder);
$this->view->setVars([ $this->view->setVars([
"files" => $files "files" => $files
]); ]);

View File

@@ -224,9 +224,13 @@ class NotesModel extends Database
$pdo = $this->linkDB(); $pdo = $this->linkDB();
if (!$pdo) return ['success' => false, 'message' => 'Database error.']; if (!$pdo) return ['success' => false, 'message' => 'Database error.'];
$uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/EIANotesApp/Uploads/'; $uploadDir = __DIR__ . '/../Uploads/';
$uploadedFileNames = []; $uploadedFileNames = [];
if (!file_exists($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
if (isset($_FILES['attachments']) && !empty($_FILES['attachments']['name'][0])) { if (isset($_FILES['attachments']) && !empty($_FILES['attachments']['name'][0])) {
$files = $_FILES['attachments']; $files = $_FILES['attachments'];
@@ -265,7 +269,7 @@ class NotesModel extends Database
$stmt->execute([$fileId]); $stmt->execute([$fileId]);
$file = $stmt->fetch(); $file = $stmt->fetch();
if ($file) { if ($file) {
$filePath = $_SERVER['DOCUMENT_ROOT'] . '/EIANotesApp/Uploads/' . $file['stored_filename']; $filePath = __DIR__ . '/../Uploads/' . $file['stored_filename'];
if (file_exists($filePath)) { if (file_exists($filePath)) {
unlink($filePath); unlink($filePath);
} }

View File

@@ -4,7 +4,7 @@ include dirname(__DIR__).'/header.phtml';
//// Test write permissions //// Test write permissions
//// This is the directory we will upload files to. //// This is the directory we will upload files to.
//$uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/EIANotesApp/Uploads/'; //$uploadDir = __DIR__ . '/../Uploads/';
//if (!file_exists($uploadDir)) { //if (!file_exists($uploadDir)) {
// mkdir($uploadDir, 0777, true); // mkdir($uploadDir, 0777, true);
//} //}

View File

@@ -74,7 +74,7 @@ function sanitize($data, $flags = ENT_QUOTES, $encoding = 'UTF-8') {
<ul> <ul>
<?php foreach($files as $file): ?> <?php foreach($files as $file): ?>
<li> <li>
<a href="/EIANotesApp/Uploads/<?php echo $file['stored_filename']; ?>" download target="_blank"><?php echo htmlspecialchars($file['original_filename']); ?></a> <a href="<?php echo substr($_SERVER['PHP_SELF'], 0, -9).'Uploads/'.$file['stored_filename']; ?>" download target="_blank"><?php echo htmlspecialchars($file['original_filename']); ?></a>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>

View File

@@ -42,7 +42,7 @@
<?php foreach ($files as $file): ?> <?php foreach ($files as $file): ?>
<tr> <tr>
<td><?php echo sanitize($file['id']); ?></td> <td><?php echo sanitize($file['id']); ?></td>
<td><a href="/EIANotesApp/Uploads/<?php echo $file['stored_filename']; ?>" download target="_blank"><?php echo sanitize($file['original_filename']); ?></a></td> <td><a href="<?php echo substr($_SERVER['PHP_SELF'], 0, -9).'Uploads/'.$file['stored_filename']; ?>"><?php echo sanitize($file['stored_filename']); ?></a></td>
<td><?php echo sanitize($file['stored_filename']); ?></td> <td><?php echo sanitize($file['stored_filename']); ?></td>
<td><?php echo sanitize($file['note_id']); ?></td> <td><?php echo sanitize($file['note_id']); ?></td>
<td><?php echo sanitize($file['owner_username']); ?></td> <td><?php echo sanitize($file['owner_username']); ?></td>

View File

@@ -33,7 +33,7 @@ $files = $this->notesModel->getUploadedFiles($note['id']);
<ul> <ul>
<?php foreach ($files as $file): ?> <?php foreach ($files as $file): ?>
<li> <li>
<a href="/EIANotesApp/Uploads/<?php echo $file['stored_filename']; ?>" download target="_blank"><?php echo htmlspecialchars($file['original_filename']); ?></a> <a href="<?php echo substr($_SERVER['PHP_SELF'], 0, -9).'Uploads/'.$file['stored_filename']; ?>" download target="_blank"><?php echo htmlspecialchars($file['original_filename']); ?></a>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>