<?php
session_start();
ob_start();
//$_SESSION['logner_bot']
	function sUrl($id)
	{
		$string = trim($id);
		$patterns = "/\s/";
		$replacements = "_";

		return preg_replace($patterns, $replacements, $string);
	}
	function uid()
	{
	$password_length = 19;
	$alfa = "1234567890abcdefghijklmnopqrstuvwxyz";
	$token = "";
	for($i = 1; $i < $password_length; $i ++) {
	  @$token .= $alfa[rand(1, strlen($alfa))];
	}    
	return $token;
	}
include_once("../hooks/_config_.php");
$conf = new config();

$session_id='1'; //$session id
$path = "../../../assets/shared/posts/";
$thumb_path = "thumb/";
function snpid()
{
$password_length = 16;
$alfa = "1234567890abcdefghijklmnopqrstuvwxyz";
$token = "";
for($i = 1; $i < $password_length; $i ++) {
  @$token .= $alfa[rand(1, strlen($alfa))];
}    
return $token;
}
//if(isset($_GET['va']) && $_GET['va'] != ''){
	$valid_formats = array("jpg", "png", "gif", "bmp");
	if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
		{
		//header('Content-type: image/jpeg');
			$name = $_FILES['photoimg']['name'];
			$size = $_FILES['photoimg']['size'];
			
			if(strlen($name))
				{
					list($txt, $ext) = explode(".", $name);
					if(in_array($ext,$valid_formats))
					{
					if($size<(1424*1424))
						{
							$actual_image_name = sUrl($name); // .".".$ext; 
							// time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
							
							$tmp = $_FILES['photoimg']['tmp_name'];
							if(move_uploaded_file($tmp, $path.$actual_image_name))
								{
					
list($width, $height, $type, $attr) = getimagesize($path.$actual_image_name);						
$newthumbname = $thumb_path.$actual_image_name;
//get the dimensions for the thumbnail
$thumb_width = $width * 0.10;
$thumb_height = $height * 0.10;
//create the thumbnail

/////////////////////////////////
/* if ($type == 'jpg') {
        $largeimage = imagecreatefromjpeg($path.$actual_image_name);
		$thumb = imagecreatetruecolor(52, 62);
		imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 52, 62, $width, $height);
		
    } else
    if ($type == 'jpeg') {
        $largeimage = imagecreatefromjpeg($path.$actual_image_name);
		$thumb = imagecreatetruecolor(52, 62);
		
		imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 52, 62, $width, $height);
	
    } else
    if ($type == 'png') {
        $largeimage = imagecreatefrompng($path.$actual_image_name);
		$thumb = imagecreatetruecolor(52, 62);
		
		imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 52, 62, $width, $height);
		
    } else
    if ($type == 'gif') {
        $largeimage = imagecreatefromgif($path.$actual_image_name);
		$thumb = imagecreatetruecolor(52, 62);
		
		imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 52, 62, $width, $height);
		
    }
 *//////////////////////////////////
//$largeimage = imagecreatefromjpeg($path.$actual_image_name);
//$thumb = imagecreatetruecolor(52, 62);
//imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, 52, 62, $width, $height);


//imagejpeg($thumb, $newthumbname);

//imagedestroy($tmp);
//imagedestroy($thumb);

///////////////////////////////////////////////////////////////
			$inst_mgdtl = "INSERT INTO _dc_trads_dtls (_dcsnp_dls, _unk_ky, _frgn_ky, _dcp_xds) 
			VALUES ('".$actual_image_name."', '".uid()."', '".uid()."', '".$_SESSION['logner_bot']."')";
			mysqli_query($conf->_conni(), $inst_mgdtl) or die(mysqli_error($conf->_conni())); //sSET profile_image='$actual_image_name' WHERE uid='$session_id'");
		
		echo "</ br>";	 
		echo "<div style='background:#CAFFCA; font-size:16px; width:780px; height:40px; padding:10px;'>
				".$_SERVER['HTTP_HOST']."/assets/shared/posts/".$actual_image_name."</div>";					
		echo "<img src='../../../assets/shared/posts/".$actual_image_name."'  class='preview'>";
					
					//echo "<img src='".$newthumbname."'  class='preview'>";
					
						
						}
						 else
							echo "failed";
						}
						else
						echo "Image file size max 15 KB Allowed";					
						}
						else
						echo "Invalid file format..";	
				}
				
			else
				echo "Please select image..!";
				
			exit;
		}
		
//} // get
?>