Files
YMS/webgui/lib/fileutils.inc
T
2026-06-24 13:46:03 +02:00

46 lines
1.4 KiB
PHP

<?php
/******************************************************************************
* YMS - Yacht Management Software
* Copyright (C) 2024-2026 Thomas Hooge
*
* SPDX-License-Identifier: WTFPL
******************************************************************************
*/
// ========== FILE FUNCTIONS ==================================================
function file_fix_filesize($docid, $filepath) {
// set filesize in database to current size in filesystem
global $pdo;
$newsize = filesize($filepath);
$sql = "UPDATE document SET docsize=? WHERE docid=?";
$params = [$newsize, $docid];
$sth = $pdo->prepare($sql);
try {
$sth->execute($params);
} catch (PDOexception $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
$g_error->Add($sql);
$g_error->Add(print_r($params, true));
}
return $newsize;
}
function file_get_docname($docid, $doctype, $extension) {
global $g_doc_typemap;
return sprintf('%s-%06d.%s', $g_doc_typemap[$doctype], $docid, $extension);
}
function dir_get_size($path) {
// gets the size of a directory in bytes recursively
$total = 0;
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)
);
foreach ($iterator as $file){
$total += $file->getSize();
}
return $total;
}