<?php
include_once 'includes.php';
include_once 'public.php';
include_once 'includes/getExtension.php';
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST") {
   $name = $_FILES['photoimg']['name'];
   $size = $_FILES['photoimg']['size'];
   $imageType=$_POST['imageType'];
   if(strlen($name)) {
	  $ext = getExtension($name);
	  if(in_array($ext,$valid_formats)) {
		 if($size<(1024*$uploadImageSize)) { // Check the image size 
			$actual_image_name = $uid.time().".".$ext; // Change the image ame
		    $tmp = $_FILES['photoimg']['tmp_name'];
            include 'includes/compressProfileImage.php';
			$style='';
		    $class='';
		    $bgSave='';
		    if($imageType == 1) {
			/* User Profile Pic */
		    $widthArray = array($TimelineProfilePX); /* Image Pixel Size*/
			$prefix='user'; /* Image Prefix */
		    foreach($widthArray as $newwidth) {
				// Compres the image using compressProfileImage.php in includes file
			    $filename=compressProfileImage($ext,$tmp,$profile_image_path,$actual_image_name,$newwidth,$prefix);
			 }
			 // Then prefix the image like user_134567.jpg
		     $final_image_name=$prefix.'_'.$actual_image_name;
			 // Upload an image 
			 $newdata=$Mat->Profile_Image_Upload($uid,$final_image_name);
			 $style='timelineIMG';
		     }
			 if($newdata) {
				 echo $bgSave.'<img src="'.$base_url.$filename.'"  id="'.$style.'" class="'.$class.'"/>';
			 } 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;
		}
		
		
?>
