<?php
    require_once ('config.php');

    define('DIRLEVELS',     3); // Levels to create user storage area
    define('CHARSPERLEVEL', 2); // 2 chars (base 36) = 36 * 36 = 1296 max dirs per dir

    /// Base 36, 6 chars, max value zzzzzz = 2176782335. Enough?

    $id = 1676782335;

    $hash = base_convert($id, 10, 36);  /// Convert to base 36

    $hash = str_pad($hash, DIRLEVELS * CHARSPERLEVEL, '0', STR_PAD_LEFT); /// Left pad with 0

    $hash = strtoupper($hash); /// Upper

    $hash = strrev($hash); /// Reverse the string

    $hash = str_split($hash, CHARSPERLEVEL); /// Split into CHARSPERLEVEL chuncks

    $userstoragearea = $CFG->dataroot . '/users/' . implode($hash, '/'); /// Calculate storage area

    echo 'userid: ' . $id . ' will have storage area ' . $userstoragearea;

?>
