Skip to content
Snippets Groups Projects
get-file-service.php 852 B
Newer Older
<?php
    include 'config.php';
    include 'session-service.php';
    include 'validation-service.php';
    $validation = checkRequest(['fileId']);
    if ($validation !== true){
        $payload = [
            'success' => false,
            'message' => '$validation'
        http_response_code(400);
        exit(json_encode($payload));
    }

    $filePath = $assetsDir.'/docs'.$_POST['fileId'];
    if (!file_exists($filePath) || is_dir($filePath)){
        $payload = [
            'success' => false,
            'message' => 'Dokument nicht gefunden'
        http_response_code(404);
        exit(json_encode($payload));
    }

    $file = json_decode(file_get_contents($filePath));
    $payload = [
        'success' => true,
        'file' => $file
    ];
    http_response_code(200);
    exit(json_encode($payload));