<?php 
foreach ($_FILES as $key=>$course) {$file=$key;}
$target_path = '../images/company/LEV_images/';
$source=$_FILES[$file]["tmp_name"];
//METADATA
$data=json_decode($_REQUEST['file'], true);
$GLOBALS["name"]=$data['meta']['userid'];
$GLOBALS["imageNo"]=$data['meta']['imageid'];

//DEBUG
//$fp = file_put_contents( 'request.log', $_REQUEST["file"]);

function resize_image($file, $temp, $target_path, $w, $h) {
$name = explode('.', $file);
$newfilename = $GLOBALS["imageNo"].'_thumb.'.$name[1];

$src = imagecreatefromjpeg($temp);
list($width,$height)=getimagesize($temp);
$x_ratio = $w / $width;
$y_ratio = $h / $height;
				
if( ($width <= $w) && ($height <= $h) ){
$tn_width = $width;
$tn_height = $height;
}elseif (($x_ratio * $height) < $h){
$tn_height = ceil($x_ratio * $height);
$tn_width = $w;
}else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $h;
}
			
$medium=imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($medium,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
imagejpeg($medium, $target_path. $newfilename, 100);
//imagedestroy($medium);
}




function large_image($file, $temp, $target_path, $w, $h) {
$name = explode('.', $file);
$newfilename = $GLOBALS["imageNo"].".".$name[1];

$src = imagecreatefromjpeg($temp);
list($width,$height)=getimagesize($temp);
$x_ratio = $w / $width;
$y_ratio = $h / $height;
				
if( ($width <= $w) && ($height <= $h) ){
$tn_width = $width;
$tn_height = $height;
}elseif (($x_ratio * $height) < $h){
$tn_height = ceil($x_ratio * $height);
$tn_width = $w;
}else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $h;
}
			
$medium=imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($medium,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
imagejpeg($medium, $target_path. $newfilename, 100);
//imagedestroy($medium);
}

$thumb = resize_image($_FILES[$file]["name"],$_FILES[$file]["tmp_name"],$target_path,350,350);
$img = large_image($_FILES[$file]["name"],$_FILES[$file]["tmp_name"],$target_path,1024,1024);

?>
        $src = '../images/company/logo.original' . $extension;

 