0); $fname = get_input('filename'); if (strlen($fname)>0) { $rid = get_input('resource_id'); $tok = get_input('upload_token'); $w = waramu_get(); if ($rid == "") { // reserve id $reserverid = $w->reserveID(); $rid = $reserverid['id'][0][0]; $res['resource_id'] = $rid; } function endsWith($haystack,$needle,$case=true) { $expectedPosition = strlen($haystack) - strlen($needle); if($case) { return strrpos($haystack, $needle, 0) === $expectedPosition; } return strripos($haystack, $needle, 0) === $expectedPosition; } $path = null; foreach ($CONFIG->curriculum_config['uploadpaths'] as $up) { foreach ($up['extensions'] as $u) { if (endsWith($fname, $u, false)) $path = $up; } } if (is_null($path)) $path = $CONFIG->curriculum_config['uploadpaths'][$CONFIG->curriculum_config['default_upload_index']]; $res['schema'] = $path['schema']; $res['action'] = $path['path']; if ($tok == "") { // get a token $tok = call_user_func($path['tokenizer'], $rid); $res['upload_token'] = $tok; } } else { $res['status'] = 1; $res['message'] = 'You didn\'t choose a file'; } print json_encode($res); ?>