<?php
include_once 'includes.php';
function getExtension($str) {
	$i = strrpos($str,".");
    if (!$i) { 
	return ""; 
	} 
    $l = strlen($str) - $i;
    $ext = substr($str,$i+1,$l);
    return $ext;
 }
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
		 $name = $_FILES['photoimg']['name'];
		 $size = $_FILES['photoimg']['size'];
		 if(strlen($name)){
			$ext = getExtension($name);
			if(in_array($ext,$valid_formats)) {
			   if($size<(50024*50024)){ // image size
				  $actual_image_name = time().$uid.".".$ext; 
				  // Change the image ame
				  $tmp = $_FILES['photoimg']['tmp_name'];
				  if(move_uploaded_file($tmp, $conversation_uploads.$actual_image_name)) {
					  // Upload an image from 
					 $data=$Mat->Conversation_Image_Upload($uid,$actual_image_name);
					 // Create new image data 
				     $newdata=$Mat->Get_Conversation_Upload_Image($uid,$actual_image_name);
				     if($newdata) {
						 echo '
						 <div class="img_prew">
						 <img src="'.$base_url.$conversation_uploads.$actual_image_name.'" width="100%" height="auto" class="preview_img" id="'.$newdata['id'].'"/>
						 </div>';
					  }
				      } else {
					    echo "Fail upload folder with read access.";
				    }
					}else
					  echo "Image file size max 1 MB";					
				    }else
					  echo "Invalid file format.";	
				}else
				echo "Please select image..!";
			exit;
		}
?>