<?php
	require_once('../../../libs/FileUpload.php');
	require_once('../../../libs/SimpleImage.php');
	
	// Functions *************************************************************************************************
	function return_bytes($val){
	    $val = trim($val);
	    $last = strtolower($val{strlen($val)-1});
	    switch($last) {
	        // The 'G' modifier is available since PHP 5.1.0
	        case 'g':
	            $val *= 1024;
	        case 'm':
	            $val *= 1024;
	        case 'k':
	            $val *= 1024;
	    }

	    return $val;
	}
	// **********************************************************************************************************
	
	$file = new uploader('en');
	$acceptable_file_types = "";
	$default_extension = "";
	$mode = 2;
	$file_name = 'Filedata';
	$path = $_POST['uploadPath'];
	
	if($file->upload($file_name, $acceptable_file_types, $default_extension)):
		$file->save_file($path, $mode);
	endif;

	if($file->error):
		$file_content = $file->error;
		$fh = fopen('error.txt', 'w');
		fwrite($fh, $file_content);
		fclose($fh);
	else:
		chmod($path.'/'.$file->file['name'], 0777);					
		$image_filename = $file->file['name'];
		
		echo $image_filename;
	endif;
?>