Add Element Document

This commit is contained in:
Pl4yep2on 2024-11-06 17:05:32 +00:00
parent 077c144d89
commit bf0ff5adc2
4 changed files with 74 additions and 0 deletions

7
appinfo/routes.php Normal file
View File

@ -0,0 +1,7 @@
<?php
return [
'routes' => [
['name' => 'page#main', 'url' => '/', 'verb' => 'GET'],
['name' => 'file#upload', 'url' => '/upload', 'verb' => 'POST']
]
];

14
css/style.css Normal file
View File

@ -0,0 +1,14 @@
#drop-zone {
width: 100%;
height: 200px;
border: 2px dashed #0078d4;
display: flex;
align-items: center;
justify-content: center;
color: #555;
}
#drop-zone.hover {
border-color: #005bb5;
background-color: #f0f8ff;
}

View File

@ -0,0 +1,42 @@
<?php
namespace OCA\WebServer\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\Files\Node;
use OCP\IRequest;
class FileController extends Controller {
public function __construct(IRequest $request) {
parent::__construct($appName, $request);
}
/**
* @NoCSRFRequired
* @NoAdminRequired
*/
public function upload() {
$uploadedFile = $this->request->getUploadedFile('file');
// Vérifiez si le fichier a été bien reçu
if (!$uploadedFile) {
return new DataResponse(['status' => 'error', 'message' => 'No file uploaded'], 400);
}
try {
// Sauvegardez le fichier dans le dossier de l'utilisateur
$userFolder = \OC::$server->getUserFolder();
$userFolder->newFile($uploadedFile['name'], file_get_contents($uploadedFile['tmp_name']));
return new DataResponse(['status' => 'success', 'filename' => $uploadedFile['name']]);
} catch (\Exception $e) {
// Loggez l'erreur pour plus de détails
\OC::$server->getLogger()->error("File upload error: " . $e->getMessage(), ['app' => 'webserver']);
return new DataResponse(['status' => 'error', 'message' => 'Failed to save file'], 500);
}
}
}

11
templates/main.php Normal file
View File

@ -0,0 +1,11 @@
<?php
script('webserver', 'dragdrop');
style('webserver', 'style');
?>
<div id="app-content">
<h3>Glisser-Déposer pour Ajouter dans Nextcloud</h3>
<div id="drop-zone">Déposez vos fichiers ici</div>
</div>