<?php 
##
#	Project: PHPDISK File Storage Solution
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: super_upload.func.php 187 2016-02-06 13:44:51Z along $
#
#	Copyright (C) 2008-2016 PHPDisk Team. All Rights Reserved.
#
##

if(!defined('IN_PHPDISK')) {
	exit('[PHPDisk] Access Denied');
}
function su_token(){
	global $settings;
	$file['name'] = $_GET['name'];
	$file['size'] = $_GET['size'];
	$file['modified'] = $_GET['modified'];
	$file['token'] = md5(json_encode($file['name'] . $file['size'].$file['modified']));
	if(! file_exists(PHPDISK_ROOT.'system/tokens/' . $file['token'] . '.phpdisk.token')){
		$file['up_size'] = 0;
		$pathInfo = pathinfo($file['name']);
		$path = PHPDISK_ROOT.$settings[file_path] . date('/Y/m/d') .'/';
		make_dir($path);
		make_dir(PHPDISK_ROOT.'system/tokens/');
		$file['filePath'] = $path . $file['token'] .strtolower(get_real_ext($pathInfo['extension']));
		su_set_token($file['token'], $file);
	}
	$result['token'] = $file['token'];
	$result['success'] = true;

	echo json_encode($result);
	exit;
}

function su_set_token($token, $data){
	file_put_contents(PHPDISK_ROOT.'system/tokens/' . $token . '.phpdisk.token', json_encode($data));
}
function su_get_token($token){
	$file = PHPDISK_ROOT.'system/tokens/' . $token . '.phpdisk.token';
	if(file_exists($file)){
		return json_decode(file_get_contents($file), true);
	}
	return false;
}
?>