<?php
include '../../../conn.php';

$title=$_POST['title'];
$description=$_POST['description'];
$usertype=$_POST['usertype'];
$authername=$_POST['authorname'];

$valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'bmp' , 'pdf' , 'doc' , 'ppt'); // valid extensions
$paththumbnail = 'images/user/'; // upload directory

$imgthumbnail = $_FILES['thumbnail']['name'];
$tmpthumbnail = $_FILES['thumbnail']['tmp_name'];
// get uploaded file's extension
$extthumbnail = strtolower(pathinfo($imgthumbnail, PATHINFO_EXTENSION));
// can upload same image using rand function
$final_imagethumbnail = rand(1000,1000000).$imgthumbnail;
// check's valid format
		if(in_array($extthumbnail, $valid_extensions)) 
		{ 
		$paththumbnail = $paththumbnail.strtolower($final_imagethumbnail); 
		move_uploaded_file($tmpthumbnail,'../../../'.$paththumbnail);
		}
$paththumbnail=$baseimage.$paththumbnail;

$path = 'images/user/'; // upload directory
$img = $_FILES['image']['name'];
$tmp = $_FILES['image']['tmp_name'];
// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
// can upload same image using rand function
$final_image = rand(1000,1000000).$img;
// check's valid format
		if(in_array($ext, $valid_extensions)) 
		{ 
		$path = $path.strtolower($final_image); 
		move_uploaded_file($tmp,'../../../'.$path);
		}
$path=$baseimage.$path;

$insert = $con->query("INSERT INTO `blog`( `title`, `description`, `autherName`, `createAt`, `thumbnail`, `image`, `userType`)  VALUES  ('$title','$description','$authername',NOW(),'$paththumbnail','$path','$usertype')");

if($insert > 0)
{ 
  echo '101';

}

else{
    echo '404';
}

?>
