<?php
include_once 'includes.php';
include_once'includes/alphaID.php';

$valid_formats = array("mp4", "MP4");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
   $name = $_FILES['videop']['name'];
   $size = $_FILES['videop']['size'];
   if(strlen($name)) {
	   $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); 
	   $name = alphaID(microtime(true) * 10000);
	   if(in_array($ext,$valid_formats)) {
	   if($size<(50024*50024)) {
		  $actual_image_name = $name;
	      $video_ext=$ext;
		   $tmp = $_FILES['videop']['tmp_name'];
		   if(move_uploaded_file($tmp, $path.$actual_image_name.'.'.$video_ext)) {
			  shell_exec("ffmpeg -i uploads/$actual_image_name.flv -f flv -s 650x390 uploads/$actual_image_name.mp4");
              shell_exec("ffmpeg -i uploads/$actual_image_name.mp4 -vcodec png -ss 00:00:15 -s 650x390 -vframes 1 -an -f rawvideo uploads/$actual_image_name.png");
			  $data=$Mat->Video_Upload($uid,$actual_image_name,$video_ext);
			  $newdata=$Mat->Get_Upload_Video($uid,$actual_image_name);
			  if($newdata) {
		         echo '<div class="img_prew"><img src="'.$base_url.$path.$actual_image_name.'.png" 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;
  }
?>