<?php
/**
 * upload_path($module) — returns ['dir' => absolute path, 'url' => relative URL]
 * Folder structure: uploads/{module}/{finyear}/
 * Requires $dbname and session to be initialised before calling.
 */
function upload_path($module) {
    global $dbname;
    $finyear = isset($_SESSION['tit_' . $dbname]) ? preg_replace('/[^a-zA-Z0-9_-]/', '', $_SESSION['tit_' . $dbname]) : 'default';
    $base    = __DIR__ . '/../uploads/';
    $dir     = $base . $module . '/' . $finyear . '/';
    $url     = 'uploads/' . $module . '/' . $finyear . '/';
    if (!is_dir($dir)) {
        mkdir($dir, 0755, true);
    }
    return ['dir' => $dir, 'url' => $url];
}
