$err = '';
$config = array();
if (!@(include_once dirname(__FILE__) . '/include/loadutils.php')) {
    $err = 'Problem loading utility script';
}
if (!$err && !load_utils('api', 'data')) {
    $err = 'Problem loading utility scripts';
}
if (!$err) {
    // pull in configuration so we can log other errors
    $config = config_get();
    $err = config_error($config);
}
if (!$err) {
    // see if the request is authenticated (does not redirect or exit)
    if (!auth_ok_callback()) {
        $err = 'Unauthenticated access';
    }
}
if (!$err) {
    // pull in other configuration and check for required input
    if (!($php_input = file_get_contents('php://input'))) {
        $err = 'JSON payload required';
    } else {
        if (!($json_object = @json_decode($php_input, TRUE))) {
            $err = 'Could not parse JSON payload';
        }
    }
    if ($config['log_api_response']) {
        log_file($php_input, $config);
    }
$err = '';
$config = array();
if (!@(include_once dirname(__FILE__) . '/include/loadutils.php')) {
    $err = 'Problem loading utility script';
}
if (!$err && !load_utils('auth', 'id', 'archive')) {
    $err = 'Problem loading utility scripts';
}
if (!$err) {
    // pull in configuration so we can log other errors
    $config = config_get();
    $err = config_error($config);
}
if (!$err) {
    // see if the user is authenticated (does not redirect or exit)
    if (!auth_ok_callback($config)) {
        $err = 'Unauthenticated access';
    }
}
if (!$err) {
    // pull in other configuration and check for required input
    $id = empty($_REQUEST['id']) ? '' : $_REQUEST['id'];
    $job = empty($_REQUEST['job']) ? '' : $_REQUEST['job'];
    $uid = empty($_REQUEST['uid']) ? '' : $_REQUEST['uid'];
    if (!($uid && $id && $job)) {
        $err = "Parameter uid, id, job required";
    }
    $media_dir = path_concat(path_concat(path_concat($config['web_root_directory'], $config['user_media_directory']), $uid), $id);
    $path_without_extension = path_concat($media_dir, $job);
}
if (!$err && empty($_FILES)) {