<?php
/**
 * MachForm
 * 
 * © 2007–2025 Appnitro Software. All rights reserved.
 * 
 * This source code is proprietary and may not be copied, modified,
 * or distributed in any form without express written permission from Appnitro Software.
 * 
 * License information: https://www.machform.com/license-agreement/
 */
	
    require('config.php');

    $folder_name = ''; //the folder name where the files will be stored under the main S3 bucket

    defined('MF_TRANSLOADIT_AUTH_KEY') or define('MF_TRANSLOADIT_AUTH_KEY','');
    defined('MF_TRANSLOADIT_AUTH_SECRET') or define('MF_TRANSLOADIT_AUTH_SECRET','');
    defined('MF_TRANSLOADIT_TEMPLATE_ID') or define('MF_TRANSLOADIT_TEMPLATE_ID','');

    //generate Transloadit signature
    $expires = gmdate('Y-m-d\TH:i:s\Z', time() + 3600); 
    
    $params = [
        'auth' => ['key' => MF_TRANSLOADIT_AUTH_KEY, 'expires' => $expires],
        'template_id' => MF_TRANSLOADIT_TEMPLATE_ID,
        'fields' => ['folder_name' => $folder_name]
    ];
    $paramsJson = json_encode($params, JSON_UNESCAPED_SLASHES);

    $sig = 'sha384:' . hash_hmac('sha384', $paramsJson, MF_TRANSLOADIT_AUTH_SECRET);

    header('Content-Type: application/json');
    echo json_encode(['params' => $paramsJson, 'signature' => $sig]);
