<?php
$valid_extensions = array('jpeg', 'jpg'); // valid extensions
$path = 'uploads/'; // upload directory
if(!empty($_POST['name']) || !empty($_POST['mitroo']) || !empty($_POST['namep']) || $_FILES['image'])
{
$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); 
if(move_uploaded_file($tmp,$path)) 
{
echo "<img src='$path' />";
$name = $_POST['name'];
$mitroo = $_POST['mitroo'];
//include database configuration file
include_once 'dbconnect.php';
//insert form data in the database
$insert = $dbcon->query("INSERT img (mitroo,filen) VALUES ('".$email."','".$path."')");
//echo $insert?'ok':'err';
}
} 
else 
{
echo 'invalid';
}
}
?>