First web gui prototype
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/******************************************************************************
|
||||
* YMS - Yacht Management Software
|
||||
* Copyright (C) 2024 Thomas Hooge
|
||||
*
|
||||
* SPDX-License-Identifier: WTFPL
|
||||
******************************************************************************/
|
||||
|
||||
/* Document Downloader
|
||||
Doucuments are not directly accessible via filesystem
|
||||
dl.php must be used with docid as parameter:
|
||||
e,g, dl.php?id=23 */
|
||||
|
||||
require 'globals.inc';
|
||||
|
||||
$docid = gpc_get_int($_GET, 'id');
|
||||
|
||||
$sql = "SELECT doctype, docsize, mimetype, hash, extension, filename FROM document WHERE docid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$docid]);
|
||||
$row = $sth->fetch();
|
||||
$dtmap = array(
|
||||
'generic' => 'doc',
|
||||
'manual' => 'man',
|
||||
'invoice' => 'inv',
|
||||
'picture' => 'pic',
|
||||
'drawing' => 'drw');
|
||||
$file = sprintf("%s/%s-%s.%s", $g_doc_basepath, $dtmap[$row['doctype']], $row['hash'], $row['extension']);
|
||||
|
||||
if (file_exists($file)) {
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: ' . $row['mimetype']);
|
||||
header('Content-Disposition: attachment; filename="' . $row['filename'] . '"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
if ($row['docsize'] == 0) {
|
||||
header('Content-Length: ' . filesize($file));
|
||||
} else {
|
||||
header('Content-Length: ' . $row['docsize']);
|
||||
}
|
||||
readfile($file);
|
||||
exit;
|
||||
} else {
|
||||
// dynamically create error image
|
||||
// TODO
|
||||
}
|
||||
Reference in New Issue
Block a user