<?php

	define('IN_HUGLO', true);
	require_once('./../includes/constants.php');
	//require_once(ROOT_PATH . 'cp/includes/sessions.php');

	$result = array();
	
	$result['time'] = date('r');
	$result['addr'] = substr_replace(gethostbyaddr($_SERVER['REMOTE_ADDR']), '******', 0, 6);
	$result['agent'] = $_SERVER['HTTP_USER_AGENT'];
	
	if (count($_GET)) {
		$result['get'] = $_GET;
	}
	if (count($_POST)) {
		$result['post'] = $_POST;
	}
	if (count($_FILES)) {
		$result['files'] = $_FILES;
	}
	
	if (file_exists('script.log') && filesize('script.log') > 102400) {
		unlink('script.log');
	}
	
	$log = @fopen('script.log', 'a');
	if ($log) {
		fputs($log, print_r($result, true) . "\n---\n");
		fclose($log);
	}
	
	
	
	$error = false;
	
	if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
		$error = 'Invalid Upload';
	}
	
	move_uploaded_file($_FILES['Filedata']['tmp_name'],  ROOT_PATH . 'videos/' . $_FILES['Filedata']['name']);
	//$return['src'] = './uploads/' . $_FILES['Filedata']['name'];
	
	
	if ($error) {
		$return = array(
			'status' => '0',
			'error' => $error
		);
	} else {
		$return = array(
			'status' => '1',
			'name' => $_FILES['Filedata']['name']
		);
	
		// Our processing, we get a hash value from the file
		$return['hash'] = $_FILES['Filedata']['tmp_name']; //md5_file();
	
		// ... and if available, we get image data
		$info = @getimagesize($_FILES['Filedata']['tmp_name']);
	
		if ($info) {
			$return['width'] = $info[0];
			$return['height'] = $info[1];
			$return['mime'] = $info['mime'];
		}
	}
	
	if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') {
		// header('Content-type: text/xml');
	
		// Really dirty, use DOM and CDATA section!
		echo '<response>';
		foreach ($return as $key => $value) {
			echo "<$key><![CDATA[$value]]></$key>";
		}
		echo '</response>';
	} else {
		// header('Content-type: application/json');
	
		echo json_encode($return);
	}

?>