31 lines
1.1 KiB
PHP
31 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../modules/shared/db.php';
|
|
require_once __DIR__ . '/../../modules/shared/auth/service.php';
|
|
require_once __DIR__ . '/../../modules/erp/lager/service.php';
|
|
|
|
$env = expand_env_values(parse_env_file(__DIR__ . '/../../../.env'));
|
|
|
|
try {
|
|
$pdo = connect_database($env);
|
|
auth_bootstrap_session();
|
|
if (auth_current_user($pdo) === null) {
|
|
http_response_code(401);
|
|
exit('Unauthorized');
|
|
}
|
|
$document = get_stock_lot_document($pdo, (int) ($_GET['id'] ?? 0));
|
|
$path = dirname(__DIR__, 2) . '/runtime/uploads/lager/' . basename((string) $document['stored_filename']);
|
|
if (!is_file($path)) {
|
|
http_response_code(404);
|
|
exit('Not Found');
|
|
}
|
|
header('Content-Type: application/octet-stream');
|
|
header('Content-Length: ' . (string) filesize($path));
|
|
header("Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode((string) $document['original_filename']));
|
|
readfile($path);
|
|
} catch (Throwable) {
|
|
http_response_code(404);
|
|
exit('Not Found');
|
|
}
|